def set_shutter_id(dev): """Set the id to the shutter.""" dev[INELS_BUS_ATTR_DICT.get( ATTR_ID)] = dev[INELS_BUS_ATTR_DICT.get(ATTR_UP)] + \ "_" + dev[INELS_BUS_ATTR_DICT.get(ATTR_DOWN)] return dev
def __roomDevicesToJson(self, room_name): """Create json object from devices listed in preffered room.""" d_type = None devices = [] raw_list = self.getRoomDevicesRaw(room_name) devices_list = raw_list.split('\n') for item in devices_list: start = len(item) - 1 end = len(item) if start > 0: if item[start:end] == ":": d_type = item[0:start] else: json_dev = item.split('" ') obj = {} obj[INELS_BUS_ATTR_DICT.get(ATTR_GROUP)] = room_name for prop in json_dev: frag = prop.split("=") obj[frag[0]] = frag[1].replace("\"", " ").strip() obj[INELS_BUS_ATTR_DICT.get( ATTR_TYPE)] = DEVICE_TYPE_DICT.get(d_type, "unknown") obj = self.__recognizeAndSetUniqueIdToDevice(obj) device = Device(obj, self) device.get_value() devices.append(device) return devices
def __recognizeAndSetUniqueIdToDevice(self, raw_device): """Some of the devices does not have unique id presented in inels attribute. We need do create one from other unique attributes.""" def set_shutter_id(dev): """Set the id to the shutter.""" dev[INELS_BUS_ATTR_DICT.get( ATTR_ID)] = dev[INELS_BUS_ATTR_DICT.get(ATTR_UP)] + \ "_" + dev[INELS_BUS_ATTR_DICT.get(ATTR_DOWN)] return dev def set_therm_id(dev): """Set the id to the therms.""" dev[INELS_BUS_ATTR_DICT.get(ATTR_ID)] = dev[ INELS_BUS_ATTR_DICT.get(ATTR_TEMP)] return dev def set_not_known_id_from_name(dev): """Set the id to the not know device from name.""" name = dev[INELS_BUS_ATTR_DICT.get(ATTR_TITLE)].replace(" ", "_") dev[INELS_BUS_ATTR_DICT.get(ATTR_ID)] = name return dev # use a switch to create identifier inside of the raw data # from usefull attributes if INELS_BUS_ATTR_DICT.get(ATTR_ID) not in raw_device: switcher = { ATTR_SHUTTER: partial(set_shutter_id, raw_device), ATTR_THERM: partial(set_therm_id, raw_device), ATTR_UNKNOWN: partial(set_not_known_id_from_name, raw_device) } fnc = switcher.get(raw_device[INELS_BUS_ATTR_DICT.get(ATTR_TYPE)]) # call selected function to set the identifier raw_device = fnc() return raw_device
def set_not_known_id_from_name(dev): """Set the id to the not know device from name.""" name = dev[INELS_BUS_ATTR_DICT.get(ATTR_TITLE)].replace(" ", "_") dev[INELS_BUS_ATTR_DICT.get(ATTR_ID)] = name return dev
def set_therm_id(dev): """Set the id to the therms.""" dev[INELS_BUS_ATTR_DICT.get(ATTR_ID)] = dev[ INELS_BUS_ATTR_DICT.get(ATTR_TEMP)] return dev
def up(self): """Shutter up of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_UP) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_UP)]
def group(self): """Group from where the object is loaded.""" if INELS_BUS_ATTR_DICT.get(ATTR_GROUP) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_GROUP)]
def read_only(self): """Read only of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_READ_ONLY) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_READ_ONLY)]
def down(self): """Shutter down of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_DOWN) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_DOWN)]
def rele(self): """Rele of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_RELE) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_RELE)]
def temperature_set(self): """Temperature of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_TEMP_SET) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_TEMP_SET)]
def type(self): """Type of the object.""" return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_TYPE)]
def title(self): """Name of the object.""" return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_TITLE)]
def id(self): """Id of the object.""" if INELS_BUS_ATTR_DICT.get(ATTR_ID) not in self.__json: return None return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_ID)]