def init(self): self._tap_sensor = sensor(baseurl=self.bridge.baseurl, id=self.id) assert self._tap_sensor.info()["type"] == "ZGPSwitch", "Sensor %s is not a Tap." % self.id self.flag = flag_sensor(baseurl=self.bridge.baseurl, name="tap-%s-flag" % self.id) self.flag.init() self.on = True #TODO read group status self.status = status_sensor(baseurl=self.bridge.baseurl, name="tap-%s-status" % self.id) self.status.init() self.status_state = self.status.state() self.bridge.create_group("tap-%s-group" % self.id, [light.id for light in self.lights]) def put_lights(**kwargs): simplekw = kwargs.copy() if "ct" in simplekw: simplekw.pop("ct") return [put_light(light.id, **(simplekw if "Dimmable" in light.type else kwargs)) for light in self.lights] def create_onoff_rule(name, btn, s0, s1): self.bridge.create_rule("tap-%s-%s" % (self.id, name), button_hit(self.id, btn) + flag_eq(self.flag.id, s0), put_lights(on=s1) + [put_flag(self.flag.id, flag=s1)]) create_onoff_rule("on", BUTTON1, "false", True) create_onoff_rule("off", BUTTON1, "true", False) def create_rule(btn, s0, s1, bri, ct): self.bridge.create_rule("tap-%s-step-%d-%d" % (self.id, s0, s1), button_hit(self.id, btn) + status_eq(self.status.id, str(s0)), put_lights(bri=bri, ct=ct) + [put_flag(self.status.id, status=s1)]) create_rule(BUTTON4, 0, 1, 127, MIREK/2600) create_rule(BUTTON4, 1, 2, 191, MIREK/3200) create_rule(BUTTON4, 2, 3, 255, MIREK/3800) create_rule(BUTTON2, 3, 2, 191, MIREK/3200) create_rule(BUTTON2, 2, 1, 127, MIREK/2600) create_rule(BUTTON2, 1, 0, 63, MIREK/2000)
async def update_sensors(self): # logger.info('test sensors !') for i, j in self.attributes.items(): # sensor_name = "tydom_alarm_sensor_"+i # logger.debug("name %s elem_name %s attributes_topic_from_device %s mqtt %s", sensor_name, i, self.config['json_attributes_topic'], self.mqtt) if not i == 'device_type' or not i == 'id': new_sensor = None new_sensor = sensor(elem_name=i, tydom_attributes_payload=self.attributes, attributes_topic_from_device=self. config['json_attributes_topic'], mqtt=self.mqtt) await new_sensor.update()
async def update_sensors(self): # print('test sensors !') for i, j in self.attributes.items(): # sensor_name = "tydom_alarm_sensor_"+i # print("name "+sensor_name, "elem_name "+i, "attributes_topic_from_device ",self.config['json_attributes_topic'], "mqtt",self.mqtt) if not i == 'device_type' or not i == 'id': new_sensor = None new_sensor = sensor(elem_name=i, tydom_attributes_payload=self.attributes, attributes_topic_from_device=self. config['json_attributes_topic'], mqtt=self.mqtt) await new_sensor.update()
async def parse_devices_data(self, parsed): for i in parsed: for endpoint in i["endpoints"]: if endpoint["error"] == 0 and len(endpoint["data"]) > 0: try: attr_alarm = {} attr_alarm_details = {} attr_cover = {} attr_cover_details = {} attr_door ={} attr_window ={} attr_light = {} attr_boiler = {} attr_light_details = {} device_id = i["id"] endpoint_id = endpoint["id"] name_of_id = self.get_name_from_id(endpoint_id) type_of_id = self.get_type_from_id(endpoint_id) _LOGGER.debug("======[ DEVICE INFOS ]======") _LOGGER.debug("ID {}".format(device_id)) _LOGGER.debug("ENDPOINT ID {}".format(endpoint_id)) _LOGGER.debug("Name {}".format(name_of_id)) _LOGGER.debug("Type {}".format(type_of_id)) _LOGGER.debug("==========================") for elem in endpoint["data"]: _LOGGER.debug("CURRENT ELEM={}".format(elem)) # endpoint_id = None elementName = None elementValue = None elementValidity = None # Element name elementName = elem["name"] # Element value elementValue = elem["value"] elementValidity = elem["validity"] print_id = None if len(name_of_id) != 0: print_id = name_of_id # endpoint_id = device_endpoint[device_id] else: print_id = device_id # endpoint_id = device_endpoint[device_id] if type_of_id == 'light': if elementName in deviceLightKeywords and elementValidity == 'upToDate': # NEW METHOD attr_light['device_id'] = device_id attr_light['endpoint_id'] = endpoint_id attr_light['id'] = str(device_id) + '_' + str(endpoint_id) attr_light['light_name'] = print_id attr_light['name'] = print_id attr_light['device_type'] = 'light' attr_light[elementName] = elementValue if type_of_id == 'shutter': if elementName in deviceCoverKeywords and elementValidity == 'upToDate': #NEW METHOD attr_cover['device_id'] = device_id attr_cover['endpoint_id'] = endpoint_id attr_cover['id'] = str(device_id)+'_'+str(endpoint_id) attr_cover['cover_name'] = print_id attr_cover['name'] = print_id attr_cover['device_type'] = 'cover' attr_cover[elementName] = elementValue if type_of_id == 'belmDoor': if elementName in deviceDoorKeywords and elementValidity == 'upToDate': #NEW METHOD attr_door['device_id'] = device_id attr_door['endpoint_id'] = endpoint_id attr_door['id'] = str(device_id)+'_'+str(endpoint_id) attr_door['door_name'] = print_id attr_door['name'] = print_id attr_door['device_type'] = 'sensor' attr_door[elementName] = elementValue if type_of_id == 'windowFrench' or type_of_id == 'window': if elementName in deviceDoorKeywords and elementValidity == 'upToDate': #NEW METHOD attr_window['device_id'] = device_id attr_window['endpoint_id'] = endpoint_id attr_window['id'] = str(device_id)+'_'+str(endpoint_id) attr_window['door_name'] = print_id attr_window['name'] = print_id attr_window['device_type'] = 'sensor' attr_window[elementName] = elementValue if type_of_id == 'boiler': if elementName in deviceBoilerKeywords and elementValidity == 'upToDate': #NEW METHOD attr_boiler['device_id'] = device_id attr_boiler['endpoint_id'] = endpoint_id attr_boiler['id'] = str(device_id)+'_'+str(endpoint_id) # attr_boiler['boiler_name'] = print_id attr_boiler['name'] = print_id attr_boiler['device_type'] = 'climate' attr_boiler[elementName] = elementValue if type_of_id == 'alarm': if elementName in deviceAlarmKeywords and elementValidity == 'upToDate': attr_alarm['device_id'] = device_id attr_alarm['endpoint_id'] = endpoint_id attr_alarm['id'] = str(device_id)+'_'+str(endpoint_id) attr_alarm['alarm_name']="Tyxal Alarm" attr_alarm['name']="Tyxal Alarm" attr_alarm['device_type'] = 'alarm_control_panel' attr_alarm[elementName] = elementValue except Exception as e: print('msg_data error in parsing !') print(e) if 'device_type' in attr_cover and attr_cover['device_type'] == 'cover': # print(attr_cover) new_cover = "cover_tydom_"+str(endpoint_id) new_cover = Cover(tydom_attributes=attr_cover, mqtt=self.mqtt_client) #NEW METHOD # new_cover = Cover(id=endpoint_id,name=print_id, current_position=elementValue, attributes=i, mqtt=self.mqtt_client) await new_cover.update() elif 'device_type' in attr_door and attr_door['device_type'] == 'sensor': # print(attr_cover) new_door = "door_tydom_"+str(endpoint_id) new_door = sensor(elem_name='openState', tydom_attributes_payload=attr_door, attributes_topic_from_device='useless', mqtt=self.mqtt_client) # new_cover = Cover(id=endpoint_id,name=print_id, current_position=elementValue, attributes=i, mqtt=self.mqtt_client) await new_door.update() elif 'device_type' in attr_window and attr_window['device_type'] == 'sensor': # print(attr_cover) new_window = "window_tydom_"+str(endpoint_id) new_window = sensor(elem_name='openState', tydom_attributes_payload=attr_window, attributes_topic_from_device='useless', mqtt=self.mqtt_client) # new_cover = Cover(id=endpoint_id,name=print_id, current_position=elementValue, attributes=i, mqtt=self.mqtt_client) await new_window.update() elif 'device_type' in attr_light and attr_light['device_type'] == 'light': # print(attr_cover) new_light = "light_tydom_"+str(endpoint_id) new_light = Light(tydom_attributes=attr_light, mqtt=self.mqtt_client) #NEW METHOD # new_cover = Cover(id=endpoint_id,name=print_id, current_position=elementValue, attributes=i, mqtt=self.mqtt_client) await new_light.update() elif 'device_type' in attr_boiler and attr_boiler['device_type'] == 'climate': # print(attr_boiler) new_boiler = "boiler_tydom_"+str(endpoint_id) new_boiler = Boiler(tydom_attributes=attr_boiler, tydom_client=self.tydom_client, mqtt=self.mqtt_client) #NEW METHOD # new_cover = Cover(id=endpoint_id,name=print_id, current_position=elementValue, attributes=i, mqtt=self.mqtt_client) await new_boiler.update() # Get last known state (for alarm) # NEW METHOD elif 'device_type' in attr_alarm and attr_alarm['device_type'] == 'alarm_control_panel': # print(attr_alarm) state = None sos_state = False maintenance_mode = False out = None try: # { # "name": "alarmState", # "type": "string", # "permission": "r", # "enum_values": ["OFF", "DELAYED", "ON", "QUIET"] # }, # { # "name": "alarmMode", # "type": "string", # "permission": "r", # "enum_values": ["OFF", "ON", "TEST", "ZONE", "MAINTENANCE"] # } if ('alarmState' in attr_alarm and attr_alarm['alarmState'] == "ON") or ('alarmState' in attr_alarm and attr_alarm['alarmState']) == "QUIET": state = "triggered" elif 'alarmState' in attr_alarm and attr_alarm['alarmState'] == "DELAYED": state = "pending" if 'alarmSOS' in attr_alarm and attr_alarm['alarmSOS'] == "true": state = "triggered" sos_state = True elif 'alarmMode' in attr_alarm and attr_alarm ["alarmMode"] == "ON": state = "armed_away" elif 'alarmMode' in attr_alarm and attr_alarm["alarmMode"] == "ZONE": state = "armed_home" elif 'alarmMode' in attr_alarm and attr_alarm["alarmMode"] == "OFF": state = "disarmed" elif 'alarmMode' in attr_alarm and attr_alarm["alarmMode"] == "MAINTENANCE": maintenance_mode = True state = "disarmed" if 'outTemperature' in attr_alarm: out = attr_alarm["outTemperature"] if (sos_state == True): print("SOS !") if not (state == None): # print(state) alarm = "alarm_tydom_"+str(endpoint_id) # print("Alarm created / updated : "+alarm) alarm = Alarm(current_state=state, tydom_attributes=attr_alarm, mqtt=self.mqtt_client) await alarm.update() except Exception as e: print("Error in alarm parsing !") print(e) pass else: pass
async def parse_devices_data(self, parsed): for i in parsed: for endpoint in i["endpoints"]: if endpoint["error"] == 0 and len(endpoint["data"]) > 0: try: attr_device = {} class_name = "Unknown" device_id = i["id"] endpoint_id = endpoint["id"] name_of_id = self.get_name_from_id(endpoint_id) type_of_id = self.get_type_from_id(endpoint_id) _LOGGER.debug("======[ DEVICE INFOS ]======") _LOGGER.debug("ID {}".format(device_id)) _LOGGER.debug("ENDPOINT ID {}".format(endpoint_id)) _LOGGER.debug("Name {}".format(name_of_id)) _LOGGER.debug("Infos {}".format(endpoint["data"])) _LOGGER.debug("Type {}".format(type_of_id)) _LOGGER.debug("==========================") print_id = None if len(name_of_id) != 0: print_id = name_of_id else: print_id = device_id attr_device['device_id'] = device_id attr_device['endpoint_id'] = endpoint_id attr_device['id'] = type_of_id + '_' + str( device_id) + '_' + str(endpoint_id) attr_device['name'] = print_id attr_device['device_type'] = type_of_id if type_of_id == 'light': attr_device['light_name'] = print_id class_name = "Light" if type_of_id == 'shutter': attr_device['cover_name'] = print_id attr_device['device_type'] = 'cover' class_name = "Cover" if type_of_id == 'belmDoor': attr_device['door_name'] = print_id attr_device['device_type'] = 'sensor' class_name = "Sensor" if type_of_id == 'windowFrench' or type_of_id == 'window': attr_device['door_name'] = print_id attr_device['device_type'] = 'window' class_name = "Window" if type_of_id == 'boiler': attr_device['device_type'] = 'climate' class_name = "Boiler" if type_of_id == 'electric' or type_of_id == 'hvac': attr_device['device_type'] = 'climate' class_name = "Electric" if type_of_id == 'alarm': attr_device['alarm_name'] = "Tyxal Alarm" attr_device['device_type'] = 'alarm_control_panel' class_name = "Alarm" for elem in endpoint["data"]: _LOGGER.debug("CURRENT ELEM={}".format(elem)) # endpoint_id = None elementName = None elementValue = None elementValidity = None elementName = elem["name"] elementValue = elem["value"] elementValidity = elem["validity"] if elementValidity == 'upToDate': attr_device[elementName] = elementValue except Exception as e: print('msg_data error in parsing !') print(e) if class_name == "Cover": new_cover = Cover(tydom_attributes=attr_device, mqtt=self.mqtt_client) await new_cover.update() elif class_name == "Sensor": new_door = sensor( elem_name='openState', tydom_attributes_payload=attr_device, attributes_topic_from_device='useless', mqtt=self.mqtt_client) await new_door.update() elif class_name == "Window": new_window = Window(tydom_attributes=attr_device, tydom_client=self.tydom_client, mqtt=self.mqtt_client) await new_window.update() elif class_name == "Unknown": new_unknown = Unknown(tydom_attributes=attr_device, tydom_client=self.tydom_client, mqtt=self.mqtt_client) await new_unknown.update() elif class_name == "Light": new_light = Light(tydom_attributes=attr_device, mqtt=self.mqtt_client) #NEW METHOD await new_light.update() elif class_name == "Boiler": new_boiler = Boiler(tydom_attributes=attr_device, tydom_client=self.tydom_client, mqtt=self.mqtt_client) #NEW METHOD await new_boiler.update() elif class_name == "Electric": new_electric = Electric( tydom_attributes=attr_device, tydom_client=self.tydom_client, mqtt=self.mqtt_client) #NEW METHOD await new_electric.update() # Get last known state (for alarm) # NEW METHOD elif class_name == "Alarm": # print(attr_alarm) state = None sos_state = False maintenance_mode = False out = None try: # { # "name": "alarmState", # "type": "string", # "permission": "r", # "enum_values": ["OFF", "DELAYED", "ON", "QUIET"] # }, # { # "name": "alarmMode", # "type": "string", # "permission": "r", # "enum_values": ["OFF", "ON", "TEST", "ZONE", "MAINTENANCE"] # } if ('alarmState' in attr_device and attr_device['alarmState'] == "ON") or ( 'alarmState' in attr_device and attr_device['alarmState']) == "QUIET": state = "triggered" elif 'alarmState' in attr_device and attr_device[ 'alarmState'] == "DELAYED": state = "pending" if 'alarmSOS' in attr_device and attr_device[ 'alarmSOS'] == "true": state = "triggered" sos_state = True elif 'alarmMode' in attr_device and attr_device[ "alarmMode"] == "ON": state = "armed_away" elif 'alarmMode' in attr_device and attr_device[ "alarmMode"] == "ZONE": state = "armed_home" elif 'alarmMode' in attr_device and attr_device[ "alarmMode"] == "OFF": state = "disarmed" elif 'alarmMode' in attr_device and attr_device[ "alarmMode"] == "MAINTENANCE": maintenance_mode = True state = "disarmed" if 'outTemperature' in attr_device: out = attr_device["outTemperature"] if (sos_state == True): print("SOS !") if not (state == None): # print(state) alarm = "alarm_tydom_" + str(endpoint_id) # print("Alarm created / updated : "+alarm) alarm = Alarm(current_state=state, tydom_attributes=attr_device, mqtt=self.mqtt_client) await alarm.update() except Exception as e: print("Error in alarm parsing !") print(e) pass else: print("ERROR : can't change configuration") pass