api: use proper connection shutdown for downstream services
This commit is contained in:
parent
0331dd6406
commit
44d484cfc1
3 changed files with 94 additions and 22 deletions
|
|
@ -84,8 +84,16 @@ class CCUJackClient:
|
|||
async def connect_mqtt(self):
|
||||
await self.mqtt.connect()
|
||||
|
||||
async def close_connections(self):
|
||||
await asyncio.gather(
|
||||
self.mqtt.disconnect(),
|
||||
self.http.close()
|
||||
)
|
||||
|
||||
async def find_locks(self):
|
||||
logger.debug("Inspecting lock devices present in CCUJack")
|
||||
|
||||
# iterate through the CCUJACK API to find all devices
|
||||
async with self.http.get("/device") as resp:
|
||||
devices = CCUDeviceList.model_validate(await resp.json())
|
||||
|
||||
|
|
@ -99,6 +107,14 @@ class CCUJackClient:
|
|||
|
||||
self.locks = [i for i in device_infos if i[0].type == DEVICE_TYPE_LOCK]
|
||||
|
||||
# update active mqtt subscriptions
|
||||
mqtt_topics = set()
|
||||
for i_lock, lock_channels in self.locks:
|
||||
for i_channel, channel_params in lock_channels:
|
||||
for i_param in channel_params:
|
||||
mqtt_topics.add(f"device/status/{i_lock.address}/{i_channel.index}/{i_param.id}")
|
||||
# await self.mqtt.update_subscriptions(mqtt_topics)
|
||||
|
||||
async def query_param_value(self, address: str):
|
||||
logger.debug("Querying parameter value from '%s'", address)
|
||||
async with self.http.get(f"/device/{address}/~pv") as resp:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue