Allow closing via mqtt
parent
28323ef0ce
commit
de22e01b69
|
@ -22,9 +22,15 @@ class Control(util.Loggable):
|
|||
self._position_task: Thread = None
|
||||
self._control_task: Thread = None
|
||||
|
||||
def handle_target(client, userdata, msg):
|
||||
self._logger().debug("Incoming MQTT message on %s: %s", msg.topic, msg.payload)
|
||||
if msg.topic == "door/state/target" and msg.payload == b'closed':
|
||||
self.close()
|
||||
|
||||
self.target = mqtt.Value(mqtt_client, "door/state/target",
|
||||
persistent=True,
|
||||
translate=state_names)
|
||||
translate=state_names,
|
||||
remote_update_callback = handle_target)
|
||||
self.state = mqtt.Value(mqtt_client, "door/state/value",
|
||||
persistent=True,
|
||||
translate=state_names)
|
||||
|
|
|
@ -19,7 +19,8 @@ class Value:
|
|||
typing.Dict[Any, str],
|
||||
typing.Callable]
|
||||
= None,
|
||||
max_update: float = 0.1):
|
||||
max_update: float = 0.1,
|
||||
remote_update_callback = None):
|
||||
self.client = client
|
||||
self.topic = topic
|
||||
self.persistent = persistent
|
||||
|
@ -39,6 +40,10 @@ class Value:
|
|||
if start_value is not None:
|
||||
self.update(start_value)
|
||||
|
||||
if remote_update_callback is not None:
|
||||
self.client.message_callback_add(self.topic, remote_update_callback)
|
||||
self.client.subscribe(self.topic, 2)
|
||||
|
||||
def update(self, value: Any, *,
|
||||
force: bool = False,
|
||||
no_update: bool = False) -> None:
|
||||
|
|
Loading…
Reference in New Issue