Beispiel #1
0
 def __init__(self):
     self.db = create_db_object()
     self.db.logger.disabled = True
     self.logger = logging.getLogger('CONF')
     self.room_id    = 0
     self.element_id = 0
     self.module_id  = 1 # address 0 is a broadcast address in modbus. Therfore id starts from 1
     self.dependancy_id = 0
     self.regulation_id = 0
     self.number_of_errors = 0
Beispiel #2
0
 def __init__(self):
     self.db = create_db_object()
     self.db.logger.disabled = True
     self.logger = logging.getLogger('CONF')
     self.room_id = 0
     self.element_id = 0
     self.module_id = 1  # address 0 is a broadcast address in modbus. Therfore id starts from 1
     self.dependancy_id = 0
     self.regulation_id = 0
     self.number_of_errors = 0
Beispiel #3
0
def system_loader():
    """Loads all necessary objects for system operation from database
    Configures system and returns system named tuple"""

    system = namedtuple("System",
                        ["clock",
                         "elements",
                         "modules",
                         "dependancies",
                         "regulations"])

    system.elements = namedtuple("elements", ['all', 'input', 'output'])
    system.modules = namedtuple("modules", ['all', 'input', 'output'])
    system.modules.input = namedtuple("input_modules", ['input_board', 'ambient_board'])
    system.modules.output = namedtuple("input_modules", ['output_board', 'led_light_board'])

    system.clock = Clock()  # instantiate global clock. Reference is stored in clock.py

    db = create_db_object()
    db.load_objects_from_table(InputElement)
    db.load_objects_from_table(OutputElement)
    db.load_objects_from_table(Blind)

    db.load_objects_from_table(OutputBoard)
    db.load_objects_from_table(LedLightBoard)
    db.load_objects_from_table(AmbientBoard)
    db.load_objects_from_table(InputBoard)

    db.load_objects_from_table(Dependancy)
    db.load_objects_from_table(Regulation)

    for element in Element.items.values():
        module = Module.items[element.module_id]
        module.elements[element.reg_id] = element  # pass elements to modules registers

    # pair blinds so two motors of the same blinds never turn on both. It would cause shortcut!
    for blind in Blind.items.values():
        other_blind_id = blind.other_blind
        blind.other_blind = Blind.items[other_blind_id]

    for dep in Dependancy.items.values():
        dep._parse_cause(all_elements=Element.items)

    for reg in Regulation.items.values():
        InputElement.items[reg.feed_el_id].subscribe(reg)

    system.elements.all = Element.items
    system.elements.input = InputElement.items
    system.elements.output = OutputElement.items
    system.modules.input = InputModule.items
    system.modules.output = OutputModule.items
    system.dependancies = Dependancy.items
    system.regulations = Regulation.items

    return system
def load_system_representation():
    db = create_db_object()  #database object
    db.load_objects_from_table(Room)
    logger = logging.getLogger('SYS_REPR_CONF')

    for room in Room.items.values():
        if room.elements:  # if there are elments in room
            elements = room.elements
            room.elements = [
            ]  #[db.read(Visual_element, 'id', int(el_num)) for el_num in room.elements.split(',')]
            for element_id in elements.split(','):
                element_data = db.read_simple(Visual_element.table_name, 'id',
                                              int(element_id))
                element_data[0] = 'e' + str(
                    element_data[0]
                )  #dodanie litery r do id zeby bylo wiadomo ze chodzi o wartosc nastawy regulacji
                room.elements.append(Visual_element(*element_data[:3]))
        else:
            room.elements = []  # so the type of room.elements is always list
        if room.regulations:  # if there are regulations in room
            regulations = room.regulations
            room.regulations = []
            for reg_id in regulations.split(','):
                reg_data = db.read_simple(Regulation.table_name, 'id',
                                          int(reg_id))
                reg_data[0] = 'r' + str(
                    reg_data[0]
                )  #dodanie litery r do id zeby bylo wiadomo ze chodzi o wartosc nastawy regulacji
                room.regulations.append(Visual_element(*reg_data[:3]))
        else:
            room.regulations = []

        for el in room.elements:  # Adds elements to groups and groups to rooms
            group_type = Group.el_to_group_map[el.type]
            group = Group(group_type)
            if group_type not in room.groups.keys():
                room.groups[group_type] = group
                group.elements.append(el)
            else:
                room.groups[group_type].elements.append(el)

        for reg in room.regulations:
            group_type = Group.el_to_group_map[reg.type]
            group = Group(group_type)
            if group_type not in room.groups.keys():
                room.groups[group_type] = group
                group.elements.append(reg)
            else:
                room.groups[group_type].elements.append(reg)
        logger.info("Loaded room: {}".format(room.id))
Beispiel #5
0
    def logout(self, data):
        self.db = create_db_object()
        db_user = self.db.read(User, 'name', data['name'])
        if db_user:
            if db_user.loged_in == True:
                db_user.loged_in = False
                self.db.update_field(db_user, 'logged_in', 0)
                self.write("ok")
                self.logger.info("LOGGED OUT: " + str(db_user)) 
                              
            else:
                self.write("error")
                self.logger.warning("USER: "******" was logged out and attempted to log out once again")   

        else:
            self.write("error")
            self.logger.warning("USER: "******" not recognized while logging out")
Beispiel #6
0
def load_system_representation():
    db = create_db_object() #database object
    db.load_objects_from_table(Room)
    logger = logging.getLogger('SYS_REPR_CONF')

    for room in Room.items.values():
        if room.elements: # if there are elments in room
            elements = room.elements
            room.elements = []#[db.read(Visual_element, 'id', int(el_num)) for el_num in room.elements.split(',')]
            for element_id in elements.split(','):
                element_data = db.read_simple(Visual_element.table_name, 'id', int(element_id))
                element_data[0] = 'e'+str(element_data[0]) #dodanie litery r do id zeby bylo wiadomo ze chodzi o wartosc nastawy regulacji
                room.elements.append(Visual_element(*element_data[:3]))
        else:
            room.elements = [] # so the type of room.elements is always list
        if room.regulations: # if there are regulations in room
            regulations = room.regulations
            room.regulations = []
            for reg_id in regulations.split(','):
                reg_data = db.read_simple(Regulation.table_name, 'id', int(reg_id))
                reg_data[0] = 'r'+str(reg_data[0]) #dodanie litery r do id zeby bylo wiadomo ze chodzi o wartosc nastawy regulacji
                room.regulations.append(Visual_element(*reg_data[:3]))
        else:
            room.regulations = []

        for el in room.elements: # Adds elements to groups and groups to rooms
            group_type = Group.el_to_group_map[el.type]
            group = Group(group_type)
            if group_type not in room.groups.keys():
                room.groups[group_type] = group
                group.elements.append(el)
            else:
                room.groups[group_type].elements.append(el)

        for reg in room.regulations:
            group_type = Group.el_to_group_map[reg.type]
            group = Group(group_type)
            if group_type not in room.groups.keys():
                room.groups[group_type] = group
                group.elements.append(reg)
            else:
                room.groups[group_type].elements.append(reg)
        logger.info("Loaded room: {}".format(room.id))
    pass
Beispiel #7
0
 def __init__(self, application, request, **kwargs):
     self.db = create_db_object()
     self.logger = logging.getLogger('AUTH')
     self.logger.disabled = False
     self.logger.setLevel(logging.INFO)
     return super().__init__(application, request, **kwargs)