def _composeDiscoveryMsg(component_topic,
                          name,
                          component_type_discovery,
                          friendly_name=None,
                          no_avail=False):
     """
     Helper function to separate dynamic system values from user defineable values.
     :param component_topic: state topic of the component. device topics (see mqtt) are supported
     :param name: name of the component, must be unique on the device, typically composed of component name and count
     :param component_type_discovery: discovery values for the component type, e.g. switch, sensor
     :param friendly_name: optional a readable name that is used in the gui and entity_id
     :param no_avail: don't add availability configs (typically only used for the availability component itself)
     :return: str
     """
     friendly_name = friendly_name or name
     component_topic = component_topic if _mqtt.isDeviceTopic(
         component_topic) is False else _mqtt.getRealTopic(component_topic)
     if no_avail is True:
         return DISCOVERY_BASE_NO_AVAIL.format(
             component_topic,  # "~" component state topic
             friendly_name,  # name
             sys_vars.getDeviceID(),
             name,  # unique_id
             component_type_discovery,  # component type specific values
             sys_vars.getDeviceDiscovery())  # device
     return DISCOVERY_BASE.format(
         component_topic,  # "~" component state topic
         friendly_name,  # name
         config.MQTT_HOME,
         sys_vars.getDeviceID(),  # availability_topic
         sys_vars.getDeviceID(),
         name,  # unique_id
         component_type_discovery,  # component type specific values
         sys_vars.getDeviceDiscovery())  # device
Exemple #2
0
 async def _discovery(self, register=True):
     name = "{!s}{!s}".format(COMPONENT_NAME, self._count)
     base_topic = _mqtt.getRealTopic(_mqtt.getDeviceTopic(name))
     modes = ujson.dumps([str(mode) for mode in self._modes])
     gc.collect()
     if register:
         sens = CLIMATE_DISCOVERY.format(
             base_topic,
             self._frn or name,
             self._composeAvailability(),
             sys_vars.getDeviceID(),
             name,  # unique_id
             _mqtt.getRealTopic(
                 self.temp_sensor.getTopic(SENSOR_TEMPERATURE)),
             # current_temp_topic
             self.temp_sensor.getTemplate(SENSOR_TEMPERATURE),
             # cur_temp_template
             self._temp_step,
             self._min_temp,
             self._max_temp,
             modes,
             sys_vars.getDeviceDiscovery())
     else:
         sens = ""
     gc.collect()
     topic = Component._getDiscoveryTopic(_COMPONENT_TYPE, name)
     await _mqtt.publish(topic, sens, qos=1, retain=True)