def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Xiaomi",
            "model": "Mijia Lywsd03Mmc",
            "name": self.format_discovery_name(name),
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "name": self.format_discovery_name(name, attr),
                "device": device,
            }

            if attr == "humidity":
                payload.update({
                    "icon": "mdi:water",
                    "unit_of_measurement": "%"
                })
            elif attr == "temperature":
                payload.update({
                    "device_class": "temperature",
                    "unit_of_measurement": "°C"
                })
            elif attr == ATTR_BATTERY:
                payload.update({
                    "device_class": "battery",
                    "unit_of_measurement": "V"
                })

            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, attr),
                    payload=payload,
                ))

        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.BINARY_SENSOR,
                self.format_discovery_topic(mac, name, ATTR_LOW_BATTERY),
                payload={
                    "unique_id":
                    self.format_discovery_id(mac, name, ATTR_LOW_BATTERY),
                    "state_topic":
                    self.format_prefixed_topic(name, ATTR_LOW_BATTERY),
                    "name":
                    self.format_discovery_name(name, ATTR_LOW_BATTERY),
                    "device":
                    device,
                    "device_class":
                    "battery",
                },
            ))

        return ret
Beispiel #2
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Meizu",
            "model": "btir",
            "name": self.format_discovery_name(mac)
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "name": self.format_discovery_name(mac, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "availability_topic": self.format_prefixed_topic(name, "availability"),
                "device_class": attr,
                "device": device
            }

            if attr == 'temperature':
                payload["unit_of_measurement"] = "°C"
            elif attr == 'humidity':
                payload["unit_of_measurement"] = "%"
            elif attr == 'battery':
                payload["unit_of_measurement"] = "%"

            ret.append(
                MqttConfigMessage(MqttConfigMessage.SENSOR, self.format_discovery_topic(mac, name, attr), payload=payload, retain=True))
        return ret
Beispiel #3
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Xiaomi",
            "model": "MiFlora",
            "name": self.format_discovery_name(mac),
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id":
                self.format_discovery_id(mac, name, attr),
                "state_topic":
                self.format_prefixed_topic(name, attr),
                "availability_topic":
                self.format_prefixed_topic(name, "availability"),
                "name":
                self.format_discovery_name(mac, attr),
                "device":
                device,
            }

            if attr == "light":
                payload.update({
                    "unique_id":
                    self.format_discovery_id(mac, name, "illuminance"),
                    "device_class":
                    "illuminance",
                    "unit_of_measurement":
                    "lux",
                })
            elif attr == "moisture":
                payload.update({
                    "icon": "mdi:water",
                    "unit_of_measurement": "%"
                })
            elif attr == "conductivity":
                payload.update({
                    "icon": "mdi:leaf",
                    "unit_of_measurement": "µS/cm"
                })
            elif attr == "temperature":
                payload.update({
                    "device_class": "temperature",
                    "unit_of_measurement": "°C"
                })
            elif attr == "battery":
                payload.update({
                    "device_class": "battery",
                    "unit_of_measurement": "%"
                })

            ret.append(
                MqttConfigMessage(MqttConfigMessage.SENSOR,
                                  self.format_discovery_topic(mac, name, attr),
                                  payload=payload,
                                  retain=True))

        return ret
Beispiel #4
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Xiaomi",
            "model": "LYWSD(CGQ/01ZM)",
            "name": self.format_discovery_name(name),
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "name": self.format_discovery_name(name, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "device_class": attr,
                "device": device,
            }

            if attr == "temperature":
                payload["unit_of_measurement"] = "°C"
            elif attr == "humidity":
                payload["unit_of_measurement"] = "%"
            elif attr == "battery":
                payload["unit_of_measurement"] = "%"

            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, attr),
                    payload=payload,
                ))

        return ret
Beispiel #5
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "bluetooth",
            "model": "rssi",
            "name": self.format_discovery_name(mac)
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "name": self.format_discovery_name(mac, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "device": device
            }
            if attr == 'rssi':
                payload["unit_of_measurement"] = "dBm"
            if attr == 'rssi_level':
                payload["unit_of_measurement"] = "L"
            ret.append(
                MqttConfigMessage(MqttConfigMessage.SENSOR,
                                  self.format_discovery_topic(mac, name, attr),
                                  payload=payload))
        return ret
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": self.format_discovery_id(mac, name),
            "manufacturer": "Sensirion AG",
            "model": "SmartGadget",
            "name": self.format_discovery_name(name),
        }

        for attr, device_class, unit in ATTR_CONFIG:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, device_class),
                "name": self.format_discovery_name(name, device_class),
                "state_topic": self.format_prefixed_topic(name, device_class),
                "device": device,
                "device_class": device_class,
                "unit_of_measurement": unit,
            }
            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, device_class),
                    payload=payload,
                ))

        return ret
Beispiel #7
0
    def config_device(self, name, mac):
        ret = []
        device = {
            'identifiers': self.format_discovery_id(mac, name),
            'manufacturer': "Sensirion AG",
            'model': "SmartGadget",
            'name': self.format_discovery_name(name),
        }

        for attr, device_class, unit in ATTR_CONFIG:
            payload = {
                'unique_id': self.format_discovery_id(mac, name, device_class),
                'name': self.format_discovery_name(name, device_class),
                'state_topic': self.format_prefixed_topic(name, device_class),
                'device': device,
                'device_class': device_class,
                'unit_of_measurement': unit,
            }
            ret.append(
                MqttConfigMessage(MqttConfigMessage.SENSOR,
                                  self.format_discovery_topic(
                                      mac, name, device_class),
                                  payload=payload))

        return ret
  def config_device(self, name, mac):
    ret = []
    device={"identifiers": [mac, self.format_id(name, separator="_")], "manufacturer": "Xiaomi", "model": "LYWSD(CGQ/01ZM)", "name": self.format_topic(name, separator=" ").title()}
    for attr in monitoredAttrs:
      payload = {"unique_id": self.format_id(name, attr, separator="_"), "state_topic": self.format_topic(name, attr), "device_class": attr, "device": device}
      ret.append(MqttConfigMessage(MqttConfigMessage.SENSOR, self.format_topic(name, attr, separator="_"), payload=payload))

    return ret
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": self.format_discovery_id(mac, name),
            "manufacturer": "Ruuvi",
            "model": "RuuviTag",
            "name": self.format_discovery_name(name),
        }

        for attr, device_class, unit in ATTR_CONFIG:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, device_class),
                "name": self.format_discovery_name(name, device_class),
                "state_topic": self.format_prefixed_topic(name, device_class),
                "device": device,
                "device_class": device_class,
                "unit_of_measurement": unit,
            }
            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, device_class),
                    payload=payload,
                ))

        # Add low battery config
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.BINARY_SENSOR,
                self.format_discovery_topic(mac, name, ATTR_LOW_BATTERY),
                payload={
                    "unique_id":
                    self.format_discovery_id(mac, name, ATTR_LOW_BATTERY),
                    "name":
                    self.format_discovery_name(name, ATTR_LOW_BATTERY),
                    "state_topic":
                    self.format_prefixed_topic(name, ATTR_LOW_BATTERY),
                    "device":
                    device,
                    "device_class":
                    "battery",
                },
            ))

        return ret
Beispiel #10
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Xiaomi",
            "model": "MiFlora",
            "name": self.format_discovery_name(name)
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "state_topic": self.format_topic(name, attr),
                "name": self.format_discovery_name(name, attr),
                "device": device
            }

            if attr == 'light':
                payload.update({
                    "unique_id":
                    self.format_discovery_id(mac, name, 'illuminance'),
                    "device_class":
                    'illuminance',
                    "unit_of_measurement":
                    "lux"
                })
            elif attr == 'moisture':
                payload.update({
                    "icon": 'mdi:water',
                    "unit_of_measurement": "%"
                })
            elif attr == 'conductivity':
                payload.update({
                    "icon": 'mdi:leaf',
                    "unit_of_measurement": "µS/cm"
                })
            elif attr == "temperature":
                payload.update({
                    "device_class": "temperature",
                    "unit_of_measurement": "°C"
                })
            elif attr == "battery":
                payload.update({
                    "device_class": "battery",
                    "unit_of_measurement": "%"
                })

            ret.append(
                MqttConfigMessage(MqttConfigMessage.SENSOR,
                                  self.format_discovery_topic(mac, name, attr),
                                  payload=payload))

        return ret
Beispiel #11
0
    def configure_device_timer(self, device_name, timer_id, timer):
        from config import settings

        if not settings.get('manager', {}).get('sensor_config'):
            return

        data = self.devices[device_name]
        device = self._get_hass_device_description(device_name)

        timer_alias = 'timer{}'.format(timer_id)

        if timer is None:
            payload = ''
        else:
            payload = {
                'unique_id':
                self.format_discovery_id('am43', device_name, data['mac'],
                                         timer_alias),
                'name':
                'AM43 Blinds ({}) Timer {}: Set to {}% at {}'.format(
                    device_name, timer_id + 1, timer['position'],
                    timer['time']),
                'availability_topic':
                self.availability_topic,
                'device':
                device,
                'state_topic':
                '~/{}'.format(timer_alias),
                'command_topic':
                '~/{}/set'.format(timer_alias),
                '~':
                self.format_prefixed_topic(device_name),
            }

        # Creepy way to do HASS sensors not only during the configuration time
        return MqttConfigMessage(
            component=settings['manager']["sensor_config"].get(
                "topic", "homeassistant"),
            name='{}/{}'.format(
                MqttConfigMessage.SWITCH,
                self.format_discovery_topic(data['mac'], device_name, 'shade',
                                            timer_alias)),
            payload=payload,
            retain=settings['manager']["sensor_config"].get("retain", True))
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Airthings",
            "model": "Wave2",
            "name": self.format_discovery_name(name),
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "name": self.format_discovery_name(name, attr),
                "device": device,
            }

            if attr == "humidity":
                payload.update({
                    "icon": "mdi:water",
                    "unit_of_measurement": "%"
                })
            elif attr == "temperature":
                payload.update({
                    "device_class": "temperature",
                    "unit_of_measurement": "°C"
                })
            elif attr == ATTR_RADON_LEVEL_STA:
                payload.update({"unit_of_measurement": VOLUME_BECQUEREL})
            elif attr == ATTR_RADON_LEVEL_LTA:
                payload.update({"unit_of_measurement": VOLUME_BECQUEREL})
            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, attr),
                    payload=payload,
                ))

        return ret
Beispiel #13
0
 def config_device(self, name, data, availability_topic):
     ret = []
     device = self._get_hass_device_description(name)
     ret.append(
         MqttConfigMessage(
             MqttConfigMessage.COVER,
             self.format_discovery_topic(data['mac'], name, 'shade'),
             payload={
                 'device_class':
                 data.get('hass_device_class', 'shade'),
                 'unique_id':
                 self.format_discovery_id('am43', name, data['mac']),
                 'name':
                 'AM43 Blinds ({})'.format(name),
                 'availability_topic':
                 "{}/{}".format(self.global_topic_prefix,
                                availability_topic),
                 'device':
                 device,
                 'position_open':
                 0 + self.target_range_scale,
                 'position_closed':
                 100 - self.target_range_scale,
                 'set_position_topic':
                 '~/targetPosition/set',
                 'position_topic':
                 '~/currentPosition',
                 'state_topic':
                 '~/positionState',
                 'command_topic':
                 '~/positionState/set',
                 '~':
                 self.format_prefixed_topic(name),
             }))
     ret.append(
         MqttConfigMessage(
             MqttConfigMessage.SENSOR,
             self.format_discovery_topic(data['mac'], name, 'shade',
                                         'battery'),
             payload={
                 'device_class':
                 'battery',
                 'unique_id':
                 self.format_discovery_id('am43', name, data['mac'],
                                          'battery'),
                 'name':
                 'AM43 Blinds ({}) battery'.format(name),
                 'availability_topic':
                 "{}/{}".format(self.global_topic_prefix,
                                availability_topic),
                 '~':
                 self.format_prefixed_topic(name),
                 'unit_of_measurement':
                 '%',
                 'state_topic':
                 '~/battery',
                 'device':
                 device,
             }))
     self.availability_topic = "{}/{}".format(self.global_topic_prefix,
                                              availability_topic)
     return ret
Beispiel #14
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "Xiaomi",
            "model": "Mijia LYWSD03MMC",
            "name": self.format_discovery_name(name),
        }

        for attr in monitoredAttrs:
            payload = {
                "unique_id": self.format_discovery_id(mac, name, attr),
                "state_topic": self.format_prefixed_topic(name, attr),
                "name": self.format_discovery_name(name, attr),
                "device": device,
            }

            if attr == "humidity":
                payload.update({
                    "device_class": "humidity",
                    "unit_of_measurement": "%"
                })
            elif attr == "temperature":
                payload.update({
                    "device_class": "temperature",
                    "unit_of_measurement": "°C"
                })
            elif attr == "battery_level":
                payload.update({
                    "device_class": "battery",
                    "unit_of_measurement": "%"
                })
            elif attr == "battery_voltage":
                payload.update({
                    "device_class": "voltage",
                    "unit_of_measurement": "V"
                })
            elif attr == "rssi":
                payload.update({
                    "device_class": "signal_strength",
                    "unit_of_measurement": "dBm"
                })

            ret.append(
                MqttConfigMessage(
                    MqttConfigMessage.SENSOR,
                    self.format_discovery_topic(mac, name, attr),
                    payload=payload,
                ))

#        ret.append(
#            MqttConfigMessage(
#                MqttConfigMessage.BINARY_SENSOR,
#                self.format_discovery_topic(mac, name, ATTR_LOW_BATTERY),
#                payload={
#                    "unique_id": self.format_discovery_id(mac, name, ATTR_LOW_BATTERY),
#                    "state_topic": self.format_prefixed_topic(name, ATTR_LOW_BATTERY),
#                    "name": self.format_discovery_name(name, ATTR_LOW_BATTERY),
#                    "device": device,
#                    "device_class": "battery",
#                },
#            )
#        )

        return ret
    def config_device(self, name, data):
        ret = []
        mac = data["mac"]
        device = {
            "identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "eQ-3",
            "model": "Smart Radiator Thermostat",
            "name": self.format_discovery_name(name),
        }

        payload = {
            "unique_id": self.format_discovery_id(mac, name, SENSOR_CLIMATE),
            "name": self.format_discovery_name(name, SENSOR_CLIMATE),
            "qos": 1,
            "temperature_state_topic": self.format_prefixed_topic(
                name, SENSOR_TARGET_TEMPERATURE
            ),
            "temperature_command_topic": self.format_prefixed_topic(
                name, SENSOR_TARGET_TEMPERATURE, "set"
            ),
            "mode_state_topic": self.format_prefixed_topic(name, "mode"),
            "mode_command_topic": self.format_prefixed_topic(name, "mode", "set"),
            "away_mode_state_topic": self.format_prefixed_topic(name, "away"),
            "away_mode_command_topic": self.format_prefixed_topic(name, "away", "set"),
            "hold_state_topic": self.format_prefixed_topic(name, "hold"),
            "hold_command_topic": self.format_prefixed_topic(name, "hold", "set"),
            "json_attributes_topic": self.format_prefixed_topic(
                name, "json_attributes"
            ),
            "min_temp": 5.0,
            "max_temp": 29.5,
            "temp_step": 0.5,
            "modes": [STATE_HEAT, STATE_AUTO, STATE_OFF],
            "hold_modes": [HOLD_BOOST, HOLD_COMFORT, HOLD_ECO],
            "device": device,
        }
        if data.get("discovery_temperature_topic"):
            payload["current_temperature_topic"] = data["discovery_temperature_topic"]
        if data.get("discovery_temperature_template"):
            payload["current_temperature_template"] = data[
                "discovery_temperature_template"
            ]
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.CLIMATE,
                self.format_discovery_topic(mac, name, SENSOR_CLIMATE),
                payload=payload,
            )
        )

        payload = {
            "unique_id": self.format_discovery_id(mac, name, SENSOR_WINDOW),
            "name": self.format_discovery_name(name, SENSOR_WINDOW),
            "state_topic": self.format_prefixed_topic(name, SENSOR_WINDOW),
            "device_class": "window",
            "payload_on": "true",
            "payload_off": "false",
            "device": device,
        }
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.BINARY_SENSOR,
                self.format_discovery_topic(mac, name, SENSOR_WINDOW),
                payload=payload,
            )
        )

        payload = {
            "unique_id": self.format_discovery_id(mac, name, SENSOR_BATTERY),
            "name": self.format_discovery_name(name, SENSOR_BATTERY),
            "state_topic": self.format_prefixed_topic(name, SENSOR_BATTERY),
            "device_class": "battery",
            "payload_on": "true",
            "payload_off": "false",
            "device": device,
        }
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.BINARY_SENSOR,
                self.format_discovery_topic(mac, name, SENSOR_BATTERY),
                payload=payload,
            )
        )

        payload = {
            "unique_id": self.format_discovery_id(mac, name, SENSOR_LOCKED),
            "name": self.format_discovery_name(name, SENSOR_LOCKED),
            "state_topic": self.format_prefixed_topic(name, SENSOR_LOCKED),
            "device_class": "lock",
            "payload_on": "false",
            "payload_off": "true",
            "device": device,
        }
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.BINARY_SENSOR,
                self.format_discovery_topic(mac, name, SENSOR_LOCKED),
                payload=payload,
            )
        )

        payload = {
            "unique_id": self.format_discovery_id(mac, name, SENSOR_VALVE),
            "name": self.format_discovery_name(name, SENSOR_VALVE),
            "state_topic": self.format_prefixed_topic(name, SENSOR_VALVE),
            "unit_of_measurement": "%",
            "device": device,
        }
        ret.append(
            MqttConfigMessage(
                MqttConfigMessage.SENSOR,
                self.format_discovery_topic(mac, name, SENSOR_VALVE),
                payload=payload,
            )
        )

        return ret
Beispiel #16
0
    def config_device(self, name, mac):
        ret = []
        device = {
            "identifiers": [mac, self.format_id(name, separator="_")],
            "manufacturer": "eQ-3",
            "model": "Smart Radiator Thermostat",
            "name": self.format_topic(name, separator=" ").title()
        }

        payload = {
            "unique_id":
            self.format_id(name, 'climate', separator="_"),
            "qos":
            1,
            "temperature_state_topic":
            self.format_topic(name, 'target_temperature'),
            "temperature_command_topic":
            self.format_topic(name, 'target_temperature', 'set'),
            "mode_state_topic":
            self.format_topic(name, 'mode'),
            "mode_command_topic":
            self.format_topic(name, 'mode', 'set'),
            "away_mode_state_topic":
            self.format_topic(name, 'away'),
            "away_mode_command_topic":
            self.format_topic(name, 'away', 'set'),
            "min_temp":
            5.0,
            "max_temp":
            29.5,
            "temp_step":
            0.5,
            "payload_on":
            "'on'",
            "payload_off":
            "'off'",
            "modes": ["heat", "auto", "manual", "eco", 'off'],
            "device":
            device
        }
        ret.append(
            MqttConfigMessage(MqttConfigMessage.CLIMATE,
                              self.format_topic(name, 'climate',
                                                separator="_"),
                              payload=payload))

        payload = {
            "unique_id": self.format_id(name, 'window_open', separator="_"),
            "state_topic": self.format_topic(name, 'window_open'),
            "device_class": 'window',
            "payload_on": "True",
            "payload_off": "False",
            "device": device
        }
        ret.append(
            MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR,
                              self.format_topic(name,
                                                'window_open',
                                                separator="_"),
                              payload=payload))

        payload = {
            "unique_id": self.format_id(name, 'low_battery', separator="_"),
            "state_topic": self.format_topic(name, 'low_battery'),
            "device_class": 'battery',
            "payload_on": "True",
            "payload_off": "False",
            "device": device
        }
        ret.append(
            MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR,
                              self.format_topic(name,
                                                'low_battery',
                                                separator="_"),
                              payload=payload))

        payload = {
            "unique_id": self.format_id(name, 'locked', separator="_"),
            "state_topic": self.format_topic(name, 'locked'),
            "device_class": 'lock',
            "payload_on": "False",
            "payload_off": "True",
            "device": device
        }
        ret.append(
            MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR,
                              self.format_topic(name, 'locked', separator="_"),
                              payload=payload))

        payload = {
            "unique_id": self.format_id(name, "valve_state", separator="_"),
            "state_topic": self.format_topic(name, "valve_state"),
            "unit_of_measurement": "%",
            "device": device
        }
        ret.append(
            MqttConfigMessage(MqttConfigMessage.SENSOR,
                              self.format_topic(name,
                                                'valve_state',
                                                separator="_"),
                              payload=payload))

        return ret
Beispiel #17
0
  def config_device(self, name, data):
    ret = []
    mac = data["mac"]
    device={"identifiers": [mac, self.format_discovery_id(mac, name)],
            "manufacturer": "eQ-3",
            "model": "Smart Radiator Thermostat",
            "name": self.format_discovery_name(name)}

    payload = {"unique_id": self.format_discovery_id(mac, name, SENSOR_CLIMATE),
               "name": self.format_discovery_name(name, SENSOR_CLIMATE),
               "qos": 1,
               "temperature_state_topic": self.format_topic(name, SENSOR_TARGET_TEMPERATURE),
               "temperature_command_topic": self.format_topic(name, SENSOR_TARGET_TEMPERATURE, 'set'),
               "mode_state_topic": self.format_topic(name, 'mode'),
               "mode_command_topic": self.format_topic(name, 'mode', 'set'),
               "away_mode_state_topic": self.format_topic(name, 'away'),
               "away_mode_command_topic": self.format_topic(name, 'away', 'set'),
               "min_temp": 5.0,
               "max_temp": 29.5,
               "temp_step": 0.5,
               "payload_on": "on",
               "payload_off": "off",
               "modes": [STATE_HEAT, STATE_AUTO, STATE_MANUAL, STATE_ECO, STATE_OFF],
               "device": device}
    if data.get("discovery_temperature_topic"):
      payload["current_temperature_topic"] = data["discovery_temperature_topic"]
    if data.get("discovery_temperature_template"):
      payload["current_temperature_template"] = data["discovery_temperature_template"]
    ret.append(MqttConfigMessage(MqttConfigMessage.CLIMATE, self.format_discovery_topic(mac, name, SENSOR_CLIMATE), payload=payload))

    payload = {"unique_id": self.format_discovery_id(mac, name, SENSOR_WINDOW),
               "name": self.format_discovery_name(name, SENSOR_WINDOW),
               "state_topic": self.format_topic(name, SENSOR_WINDOW),
               "device_class": 'window',
               "payload_on": "True",
               "payload_off": "False",
               "device": device}
    ret.append(MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR, self.format_discovery_topic(mac, name, SENSOR_WINDOW), payload=payload))

    payload = {"unique_id": self.format_discovery_id(mac, name, SENSOR_BATTERY),
               "name": self.format_discovery_name(name, SENSOR_BATTERY),
               "state_topic": self.format_topic(name, SENSOR_BATTERY),
               "device_class": 'battery',
               "payload_on": "True",
               "payload_off": "False",
               "device": device}
    ret.append(MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR, self.format_discovery_topic(mac, name, SENSOR_BATTERY), payload=payload))

    payload = {"unique_id": self.format_discovery_id(mac, name, SENSOR_LOCKED),
               "name": self.format_discovery_name(name, SENSOR_LOCKED),
               "state_topic": self.format_topic(name, SENSOR_LOCKED),
               "device_class": 'lock',
               "payload_on": "False",
               "payload_off": "True",
               "device": device}
    ret.append(MqttConfigMessage(MqttConfigMessage.BINARY_SENSOR, self.format_discovery_topic(mac, name, SENSOR_LOCKED),
                                 payload=payload))

    payload = {"unique_id": self.format_discovery_id(mac, name, SENSOR_VALVE),
               "name": self.format_discovery_name(name, SENSOR_VALVE),
               "state_topic": self.format_topic(name, SENSOR_VALVE),
               "unit_of_measurement": "%",
               "device": device}
    ret.append(MqttConfigMessage(MqttConfigMessage.SENSOR, self.format_discovery_topic(mac, name, SENSOR_VALVE), payload=payload))

    return ret
Beispiel #18
0
 def config_device(self, name, data, availability_topic):
     ret = []
     device = {
         'identifiers':
         [data['mac'],
          self.format_discovery_id(data['mac'], name)],
         'manufacturer':
         'A-OK',
         'model':
         'AM43',
         'name':
         self.format_discovery_name(name),
     }
     ret.append(
         MqttConfigMessage(
             MqttConfigMessage.COVER,
             self.format_discovery_topic(data['mac'], name, 'shade'),
             payload={
                 'device_class':
                 'blind',
                 'unique_id':
                 self.format_discovery_id('am43', name, data['mac']),
                 'name':
                 'Blinds',
                 'availability_topic':
                 "{}/{}".format(self.global_topic_prefix,
                                availability_topic),
                 'device':
                 device,
                 'position_open':
                 0 + self.target_range_scale,
                 'position_closed':
                 100 - self.target_range_scale,
                 'set_position_topic':
                 '~/targetPosition/set',
                 'position_topic':
                 '~/currentPosition',
                 'state_topic':
                 '~/positionState',
                 'command_topic':
                 '~/positionState/set',
                 '~':
                 self.format_prefixed_topic(name),
             }))
     ret.append(
         MqttConfigMessage(
             MqttConfigMessage.SENSOR,
             self.format_discovery_topic(data['mac'], name, 'shade',
                                         'battery'),
             payload={
                 'device_class':
                 'battery',
                 'unique_id':
                 self.format_discovery_id('am43', name, data['mac'],
                                          'battery'),
                 'name':
                 'Battery',
                 'availability_topic':
                 "{}/{}".format(self.global_topic_prefix,
                                availability_topic),
                 '~':
                 self.format_prefixed_topic(name),
                 'unit_of_measurement':
                 '%',
                 'state_topic':
                 '~/battery',
                 'device':
                 device,
             }))
     return ret