Skip to content

Commit

Permalink
Move calls to create_devices and start_connection_checker (#181)
Browse files Browse the repository at this point in the history
* Move calls to create_devices and start_connection_checker

* Fix docstring
  • Loading branch information
SukramJ authored Jan 14, 2022
1 parent 3737d8b commit b703252
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 0.22.0 (2022-01-14)
- Move client management to central
- Add rooms
- Move calls to create_devices and start_connection_checker

Version 0.21.2 (2022-01-13)
- Add ERROR_LOCK form HmIP-DLD
Expand Down
2 changes: 0 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ async def example_run(self):
),
]
await self.central.create_clients(client_configs)
# Clients have to exist prior to creating the devices
self.central.create_devices()
# Once the central_1 is running we subscribe to receive messages.
await self.central.init_clients()

Expand Down
13 changes: 8 additions & 5 deletions hahomematic/central_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def load_caches(self) -> None:
_LOGGER.warning("Failed to load caches.")
await self.clear_all()

def create_devices(self) -> None:
def _create_devices(self) -> None:
"""Create the devices."""
if not self._clients:
raise Exception("No clients initialized. Not starting central_unit.")
Expand Down Expand Up @@ -343,7 +343,7 @@ async def stop(self) -> None:
del hm_data.INSTANCES[self.instance_name]

async def create_clients(self, client_configs: set[hm_client.ClientConfig]) -> None:
"""Create clients for the central unit."""
"""Create clients for the central unit. Start connection checker afterwards"""

for client_config in client_configs:
try:
Expand All @@ -358,6 +358,7 @@ async def create_clients(self, client_configs: set[hm_client.ClientConfig]) -> N
self._clients_by_init_url[client.init_url] = []
self._clients_by_init_url[client.init_url].append(client)
await self.rooms.load()
self._create_devices()
except HaHomematicException as ex:
_LOGGER.debug(
"CentralUnit.create_clients: Failed to create interface %s to central. (%s)",
Expand All @@ -366,10 +367,12 @@ async def create_clients(self, client_configs: set[hm_client.ClientConfig]) -> N
)

async def init_clients(self) -> None:
"""Init clients of control unit."""
"""Init clients of control unit, and start connection checker."""
for client in self._clients.values():
await client.proxy_init()

self._start_connection_checker()

def create_task(self, target: Awaitable) -> None:
"""Add task to the executor pool."""
self.loop.call_soon_threadsafe(self.async_create_task, target)
Expand All @@ -388,7 +391,7 @@ async def async_add_executor_job(
"""Add an executor job from within the event loop."""
return await self.loop.run_in_executor(None, executor_func, *args)

def start_connection_checker(self) -> None:
def _start_connection_checker(self) -> None:
"""Start the connection checker."""
if self.model is not BACKEND_PYDEVCCU:
self._connection_checker.start()
Expand Down Expand Up @@ -711,7 +714,7 @@ async def clear(self) -> None:
self._rooms.clear()

async def _get_all_rooms(self) -> dict[str, str]:
"""Get all rooms from CCU / Homegear."""
"""Get all rooms, if available."""
if client := self._central.get_client():
return await client.get_all_rooms()
return {}
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def get_all_system_variables(self) -> dict[str, Any]:

@abstractmethod
async def get_all_rooms(self) -> dict[str, str]:
"""Get all rooms from CCU / Homegear."""
"""Get all rooms, if available."""
...

@abstractmethod
Expand Down Expand Up @@ -530,7 +530,7 @@ async def get_all_system_variables(self) -> dict[str, Any]:
return variables

async def get_all_rooms(self) -> dict[str, str]:
"""Get all rooms from CCU / Homegear."""
"""Get all rooms from CCU."""
rooms: dict[str, str] = {}
device_channel_ids = await self._get_device_channel_ids()
channel_ids_room = await self._get_all_channel_ids_room()
Expand Down
1 change: 0 additions & 1 deletion hahomematic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from abc import ABC, abstractmethod
from collections.abc import Callable
from copy import copy
from datetime import datetime
import logging
from typing import Any, Generic, TypeVar, Union, cast
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ def systemcallback(src, *args):
name="hm",
port=2001,
)])

# Clients have to exist prior to creating the devices
central_unit.create_devices()
# Once the central_1 is running we subscribe to receive messages.
await central_unit.init_clients()
await central_unit.init_hub()
Expand Down

0 comments on commit b703252

Please sign in to comment.