1 """Code to handle a Pulse Hub."""
3 from __future__
import annotations
6 from collections.abc
import Callable
14 from .const
import ACMEDA_ENTITY_REMOVE, ACMEDA_HUB_UPDATE, LOGGER
15 from .helpers
import update_devices
19 """Manages a single Pulse Hub."""
23 def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) ->
None:
24 """Initialize the system."""
27 self.tasks: list[asyncio.Task[
None]] = []
28 self.current_rollers: dict[int, aiopulse.Roller] = {}
29 self.cleanup_callbacks: list[Callable[[],
None]] = []
33 """Return the title of the hub shown in the integrations list."""
34 return f
"{self.api.id} ({self.api.host})"
38 """Return the host of this hub."""
42 """Set up a hub based on host parameter."""
43 self.
apiapi = hub = aiopulse.Hub(self.
hosthost)
46 self.tasks.append(asyncio.create_task(hub.run()))
48 LOGGER.debug(
"Hub setup complete")
52 """Reset this hub to default state."""
54 for cleanup_callback
in self.cleanup_callbacks:
58 if self.
apiapi
is None:
62 await self.
apiapi.stop()
67 await asyncio.wait(self.tasks)
72 """Evaluate entities when hub reports that update has occurred."""
73 LOGGER.debug(
"Hub {update_type.name} updated")
75 if update_type == aiopulse.UpdateType.rollers:
77 self.
hasshass.config_entries.async_update_entry(
82 self.
hasshass, ACMEDA_HUB_UPDATE.format(self.
config_entryconfig_entry.entry_id)
85 for unique_id
in list(self.current_rollers):
86 if unique_id
not in self.
apiapi.rollers:
87 LOGGER.debug(
"Notifying remove of %s", unique_id)
88 self.current_rollers.pop(unique_id)
90 self.
hasshass, ACMEDA_ENTITY_REMOVE.format(unique_id)
None __init__(self, HomeAssistant hass, ConfigEntry config_entry)
None async_notify_update(self, aiopulse.UpdateType update_type)
bool async_setup(self, int tries=0)
None update_devices(HomeAssistant hass, ConfigEntry config_entry, dict[int, Roller] api)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)