Update dynalite library and minor changes (#34618)
This commit is contained in:
parent
71617e8e8b
commit
4afa2a2651
8 changed files with 15 additions and 22 deletions
|
@ -1,21 +1,16 @@
|
|||
"""Code to handle a Dynalite bridge."""
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from dynalite_devices_lib.dynalite_devices import DynaliteDevices
|
||||
from dynalite_devices_lib.dynalite_devices import DynaliteBaseDevice, DynaliteDevices
|
||||
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import CONF_ALL, ENTITY_PLATFORMS, LOGGER
|
||||
from .const import ENTITY_PLATFORMS, LOGGER
|
||||
from .convert_config import convert_config
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from dynalite_devices_lib.dynalite_devices import ( # pylint: disable=ungrouped-imports
|
||||
DynaliteBaseDevice,
|
||||
)
|
||||
|
||||
|
||||
class DynaliteBridge:
|
||||
"""Manages a single Dynalite bridge."""
|
||||
|
@ -45,7 +40,7 @@ class DynaliteBridge:
|
|||
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
|
||||
self.dynalite_devices.configure(convert_config(config))
|
||||
|
||||
def update_signal(self, device: "DynaliteBaseDevice" = None) -> str:
|
||||
def update_signal(self, device: Optional[DynaliteBaseDevice] = None) -> str:
|
||||
"""Create signal to use to trigger entity update."""
|
||||
if device:
|
||||
signal = f"dynalite-update-{self.host}-{device.unique_id}"
|
||||
|
@ -54,9 +49,9 @@ class DynaliteBridge:
|
|||
return signal
|
||||
|
||||
@callback
|
||||
def update_device(self, device: "DynaliteBaseDevice") -> None:
|
||||
def update_device(self, device: Optional[DynaliteBaseDevice] = None) -> None:
|
||||
"""Call when a device or all devices should be updated."""
|
||||
if device == CONF_ALL:
|
||||
if not device:
|
||||
# This is used to signal connection or disconnection, so all devices may become available or not.
|
||||
log_string = (
|
||||
"Connected" if self.dynalite_devices.connected else "Disconnected"
|
||||
|
@ -73,7 +68,7 @@ class DynaliteBridge:
|
|||
if platform in self.waiting_devices:
|
||||
self.async_add_devices[platform](self.waiting_devices[platform])
|
||||
|
||||
def add_devices_when_registered(self, devices: List["DynaliteBaseDevice"]) -> None:
|
||||
def add_devices_when_registered(self, devices: List[DynaliteBaseDevice]) -> None:
|
||||
"""Add the devices to HA if the add devices callback was registered, otherwise queue until it is."""
|
||||
for platform in ENTITY_PLATFORMS:
|
||||
platform_devices = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue