|
@@ -27,7 +27,9 @@ from switchbot_mqtt._actors.base import _MQTTCallbackUserdata
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
-_MQTT_AVAILABILITY_TOPIC = "switchbot_mqtt/status"
|
|
+_MQTT_AVAILABILITY_TOPIC = "switchbot-mqtt/status"
|
|
|
|
+
|
|
|
|
+_MQTT_AVAILABILITY_TOPIC_LEGACY = "switchbot_mqtt/status"
|
|
|
|
|
|
|
|
|
|
_MQTT_BIRTH_PAYLOAD = "online"
|
|
_MQTT_BIRTH_PAYLOAD = "online"
|
|
@@ -52,11 +54,12 @@ def _mqtt_on_connect(
|
|
else mqtt_broker_host,
|
|
else mqtt_broker_host,
|
|
mqtt_broker_port,
|
|
mqtt_broker_port,
|
|
)
|
|
)
|
|
- mqtt_client.publish(
|
|
+ for topic in (_MQTT_AVAILABILITY_TOPIC, _MQTT_AVAILABILITY_TOPIC_LEGACY):
|
|
- topic=userdata.mqtt_topic_prefix + _MQTT_AVAILABILITY_TOPIC,
|
|
+ mqtt_client.publish(
|
|
- payload=_MQTT_BIRTH_PAYLOAD,
|
|
+ topic=userdata.mqtt_topic_prefix + topic,
|
|
- retain=True,
|
|
+ payload=_MQTT_BIRTH_PAYLOAD,
|
|
- )
|
|
+ retain=True,
|
|
|
|
+ )
|
|
_ButtonAutomator.mqtt_subscribe(mqtt_client=mqtt_client, settings=userdata)
|
|
_ButtonAutomator.mqtt_subscribe(mqtt_client=mqtt_client, settings=userdata)
|
|
_CurtainMotor.mqtt_subscribe(mqtt_client=mqtt_client, settings=userdata)
|
|
_CurtainMotor.mqtt_subscribe(mqtt_client=mqtt_client, settings=userdata)
|
|
|
|
|
|
@@ -95,11 +98,12 @@ def _run(
|
|
mqtt_client.username_pw_set(username=mqtt_username, password=mqtt_password)
|
|
mqtt_client.username_pw_set(username=mqtt_username, password=mqtt_password)
|
|
elif mqtt_password:
|
|
elif mqtt_password:
|
|
raise ValueError("Missing MQTT username")
|
|
raise ValueError("Missing MQTT username")
|
|
- mqtt_client.will_set(
|
|
+ for topic in (_MQTT_AVAILABILITY_TOPIC, _MQTT_AVAILABILITY_TOPIC_LEGACY):
|
|
- topic=mqtt_topic_prefix + _MQTT_AVAILABILITY_TOPIC,
|
|
+ mqtt_client.will_set(
|
|
- payload=_MQTT_LAST_WILL_PAYLOAD,
|
|
+ topic=mqtt_topic_prefix + topic,
|
|
- retain=True,
|
|
+ payload=_MQTT_LAST_WILL_PAYLOAD,
|
|
- )
|
|
+ retain=True,
|
|
|
|
+ )
|
|
mqtt_client.connect(host=mqtt_host, port=mqtt_port)
|
|
mqtt_client.connect(host=mqtt_host, port=mqtt_port)
|
|
|
|
|
|
mqtt_client.loop_forever()
|
|
mqtt_client.loop_forever()
|