示例#1
0
        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
示例#2
0
    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
示例#3
0
    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
示例#4
0
        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
示例#5
0
        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
示例#6
0
 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)]
示例#7
0
 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)]
示例#8
0
 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)]
示例#9
0
 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)]
示例#10
0
 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)]
示例#11
0
 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)]
示例#12
0
 def type(self):
     """Type of the object."""
     return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_TYPE)]
示例#13
0
 def title(self):
     """Name of the object."""
     return self.__json[INELS_BUS_ATTR_DICT.get(ATTR_TITLE)]
示例#14
0
 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)]