Пример #1
0
 def drive(self):
     Electric.drive(self, 1)
Пример #2
0
    async def parse_devices_data(self, parsed):
        #print('parse_devices_data atteint ...', parsed)

        for i in parsed:
            if i["endpoints"][0]["error"] == 0:
                try:
                    attr_alarm = {}
                    attr_alarm_details = {}
                    attr_cover = {}
                    attr_cover_details = {}

                    attr_light = {}
                    attr_light_details = {}

                    attr_electric = {}

                    device_id = i["id"]
                    name_of_id = self.get_name_from_id(device_id)
                    type_of_id = self.get_type_from_id(device_id)
                    #print('id - {} name - {} type - {}'.format(device_id,name_of_id,type_of_id))
                    for elem in i["endpoints"][0]["data"]:
                        endpoint_id = None

                        elementName = None
                        elementValue = None
                        elementValidity = None

                        # Get full name of this id
                        # endpoint_id = i["endpoints"][0]["id"]

                        # 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 == 'electric':
                            #if elementName not in deviceElectricKeywords:
                            #   pass
                            if elementName in deviceElectricKeywords and elementValidity == 'upToDate':  # NEW METHOD

                                for clef, valeur in self.devices.items():
                                    #print('{}-- valeur {} clef  {} '.format(endpoint_id,valeur,clef))
                                    if int(clef) == int(endpoint_id):
                                        attr_electric['idx'] = valeur

                                attr_electric['device_id'] = device_id
                                attr_electric['endpoint_id'] = endpoint_id
                                attr_electric['id'] = str(
                                    device_id) + '_' + str(endpoint_id)
                                attr_electric['electric_name'] = print_id
                                attr_electric['name'] = print_id
                                attr_electric['device_type'] = 'electric'
                                attr_electric[elementName] = elementValue
                                #print(attr_electric)
                except Exception as e:
                    logger_info.info(
                        "msg_data error in parsing : {}".format(e))

                if 'device_type' in attr_electric and attr_electric[
                        'device_type'] == 'electric':
                    new_electric = "electric_tydom_" + str(endpoint_id)
                    #Instanciation. la valeur du thermicLevel est celle de Tydom
                    new_electric = Electric(tydom_attributes=attr_electric,
                                            mqtt=self.mqtt_client)
                    await new_electric.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:
                        logger_info.info('Alarme je passe')
                    except Exception as e:
                        logger_info.info(
                            "Error in alarm parsing : {}".format(e))
                        pass
                else:
                    pass
Пример #3
0
 def __init__(self):
     Vehicle.__init__(self, "Nissan", "Leaf", 50, 4)
     Electric.__init__(self, 45)
Пример #4
0
    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
Пример #5
0
 def __init__(self):
     Vehicle.__init__(self, "Subaru", "Crosstrek", 60, 4)
     Gas.__init__(self, 40)
     Electric.__init__(self, 6)
Пример #6
0
 def drive(self):
     Electric.drive(self, 2)
     Gas.drive(self, 0.5)
Пример #7
0
 def refuel(self):
     Electric.refuel(self)
     Gas.refuel(self)