unixorn / ha-mqtt-discoverable

Python module to create MQTT entities that are automatically discovered by Home Assistant
Apache License 2.0
89 stars 21 forks source link

[BUG] Command topic of a Subscriber is created without the `hmd` topic prefix #149

Closed hlehoux2021 closed 8 months ago

hlehoux2021 commented 8 months ago

Describe the bug When creating a Text sensor, the topic for the command (Subscriber class) is created under the root topic , without the prefix

To Reproduce Create a Text sensor Look at the config published in homeassistant/text/device-name/sensor-name/config

example: {"component": "text", "device": {"name": "10.0.4.169", "identifiers": ["2225410"]}, "name": "KT", "unique_id": "kt", "max": 255, "min": 0, "mode": "text", "state_topic": "hmd/text/10-0-4-169/KT/state", "json_attributes_topic": "hmd/text/10-0-4-169/KT/attributes", "command_topic": "text/10-0-4-169/KT/command"}

Expected behavior expected config with the same example: {"component": "text", "device": {"name": "10.0.4.169", "identifiers": ["2225410"]}, "name": "KT", "unique_id": "kt", "max": 255, "min": 0, "mode": "text", "state_topic": "hmd/text/10-0-4-169/KT/state", "json_attributes_topic": "hmd/text/10-0-4-169/KT/attributes", "command_topic": "hmd/text/10-0-4-169/KT/command"}

Desktop (please complete the following information):

Additional context Suggested: in class Subscriber(Discoverable[EntityType]) init

Define the command topic to receive commands from HA, using hmd topic prefix

    self._command_topic = f"{self._settings.mqtt.state_prefix}/{self._entity_topic}/command"
unixorn commented 8 months ago

Closed by https://github.com/unixorn/ha-mqtt-discoverable/pull/150