mirror of
https://github.com/fmtr/haco.git
synced 2026-10-26 19:01:51 -04:00
Stop automatically publishing state on announce, and add separate initialise method for announce+state
Some checks failed
Version and Deploy / build (push) Has been cancelled
Some checks failed
Version and Deploy / build (push) Has been cancelled
This commit is contained in:
parent
911b75a295
commit
74f967f7f9
4 changed files with 13 additions and 16 deletions
|
|
@ -34,7 +34,7 @@ class ClientHaco(mqtt.Client):
|
|||
payload = message.payload.decode()
|
||||
logger.info(f"{message.topic.value}{Constants.ARROW}{payload}")
|
||||
topic_command = self.device.subscriptions[message.topic.value]
|
||||
echo_val = await topic_command.handle(message)
|
||||
await topic_command.handle(message)
|
||||
|
||||
|
||||
|
||||
|
|
@ -42,15 +42,10 @@ class ClientHaco(mqtt.Client):
|
|||
while True:
|
||||
try:
|
||||
async with self:
|
||||
|
||||
await self.device.announce()
|
||||
|
||||
await self.device.initialise()
|
||||
await self.publish(self.will.topic, self.ONLINE, retain=True)
|
||||
|
||||
# await self.publish('haco/development/3012edb1a6d4-1ed9c3469373/dev-device/dev-climate-b/power/command', "OFF", retain=True)
|
||||
|
||||
await self.handle()
|
||||
|
||||
except aiomqtt.MqttError as e:
|
||||
logger.info(f"⚠️ MQTT disconnected: {e}; retrying in 5s")
|
||||
logger.info(f"MQTT disconnected: {e}; retrying in 5s")
|
||||
await asyncio.sleep(5)
|
||||
|
|
|
|||
|
|
@ -98,7 +98,11 @@ class Control(Base, Generic[DeviceT]):
|
|||
return data
|
||||
|
||||
async def initialise(self):
|
||||
...
|
||||
await self.announce()
|
||||
for capability in self.capabilities:
|
||||
if not capability.state:
|
||||
continue
|
||||
await capability.state.handle(value=None)
|
||||
|
||||
async def announce(self):
|
||||
"""
|
||||
|
|
@ -111,11 +115,6 @@ class Control(Base, Generic[DeviceT]):
|
|||
logger.info(f'Announcing {topic} with {data_json}')
|
||||
await self.device.client.publish(topic, data_json, retain=True)
|
||||
|
||||
for capability in self.capabilities:
|
||||
if not capability.state:
|
||||
continue
|
||||
await capability.state.handle(value=None)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ class Device(Base):
|
|||
controls: List[Control] = field(default_factory=list, metadata=dict(exclude=True))
|
||||
|
||||
parent: ClientHaco | None = field(metadata=dict(exclude=True), init=False)
|
||||
# announce: dict | None = field(default=None, metadata=dict(exclude=True), init=False)
|
||||
subscriptions: dict | None = field(default=None, metadata=dict(exclude=True), init=False)
|
||||
|
||||
|
||||
|
|
@ -52,6 +51,10 @@ class Device(Base):
|
|||
for control in self.controls:
|
||||
await control.announce()
|
||||
|
||||
async def initialise(self):
|
||||
for control in self.controls:
|
||||
await control.initialise()
|
||||
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
0.1.3
|
||||
0.1.4
|
||||
Loading…
Add table
Add a link
Reference in a new issue