From 4afa2a2651038e924dbeffc9398a64fec0865f6d Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Fri, 24 Apr 2020 19:30:45 +0300 Subject: [PATCH] Update dynalite library and minor changes (#34618) --- homeassistant/components/dynalite/__init__.py | 2 +- homeassistant/components/dynalite/bridge.py | 19 +++++++------------ homeassistant/components/dynalite/const.py | 1 - .../components/dynalite/convert_config.py | 6 +++--- .../components/dynalite/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/dynalite/test_bridge.py | 3 +-- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/dynalite/__init__.py b/homeassistant/components/dynalite/__init__.py index 2f2ed8f2fa2..78281f56f0f 100644 --- a/homeassistant/components/dynalite/__init__.py +++ b/homeassistant/components/dynalite/__init__.py @@ -117,7 +117,7 @@ AREA_DATA_SCHEMA = vol.Schema( vol.All( { vol.Required(CONF_NAME): cv.string, - vol.Optional(CONF_TEMPLATE): cv.string, + vol.Optional(CONF_TEMPLATE): vol.In(DEFAULT_TEMPLATES), vol.Optional(CONF_FADE): vol.Coerce(float), vol.Optional(CONF_NO_DEFAULT): cv.boolean, vol.Optional(CONF_CHANNEL): CHANNEL_SCHEMA, diff --git a/homeassistant/components/dynalite/bridge.py b/homeassistant/components/dynalite/bridge.py index 09cf8e25a10..522061a85aa 100644 --- a/homeassistant/components/dynalite/bridge.py +++ b/homeassistant/components/dynalite/bridge.py @@ -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 = [ diff --git a/homeassistant/components/dynalite/const.py b/homeassistant/components/dynalite/const.py index ade167e1b3e..82d66dba7ba 100644 --- a/homeassistant/components/dynalite/const.py +++ b/homeassistant/components/dynalite/const.py @@ -14,7 +14,6 @@ CONF_ACTIVE = "active" ACTIVE_INIT = "init" ACTIVE_OFF = "off" ACTIVE_ON = "on" -CONF_ALL = "ALL" CONF_AREA = "area" CONF_AUTO_DISCOVER = "autodiscover" CONF_BRIDGES = "bridges" diff --git a/homeassistant/components/dynalite/convert_config.py b/homeassistant/components/dynalite/convert_config.py index 03ece744d41..2e21d5edd9b 100644 --- a/homeassistant/components/dynalite/convert_config.py +++ b/homeassistant/components/dynalite/convert_config.py @@ -34,9 +34,9 @@ from .const import ( CONF_MAP = { CONF_ACTIVE: dyn_const.CONF_ACTIVE, - ACTIVE_INIT: dyn_const.CONF_ACTIVE_INIT, - ACTIVE_OFF: dyn_const.CONF_ACTIVE_OFF, - ACTIVE_ON: dyn_const.CONF_ACTIVE_ON, + ACTIVE_INIT: dyn_const.ACTIVE_INIT, + ACTIVE_OFF: dyn_const.ACTIVE_OFF, + ACTIVE_ON: dyn_const.ACTIVE_ON, CONF_AREA: dyn_const.CONF_AREA, CONF_AUTO_DISCOVER: dyn_const.CONF_AUTO_DISCOVER, CONF_CHANNEL: dyn_const.CONF_CHANNEL, diff --git a/homeassistant/components/dynalite/manifest.json b/homeassistant/components/dynalite/manifest.json index 39f72f57b06..581110ba583 100644 --- a/homeassistant/components/dynalite/manifest.json +++ b/homeassistant/components/dynalite/manifest.json @@ -4,5 +4,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/dynalite", "codeowners": ["@ziv1234"], - "requirements": ["dynalite_devices==0.1.39"] + "requirements": ["dynalite_devices==0.1.40"] } diff --git a/requirements_all.txt b/requirements_all.txt index b9413514789..6a9dba029a7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -481,7 +481,7 @@ dsmr_parser==0.18 dweepy==0.3.0 # homeassistant.components.dynalite -dynalite_devices==0.1.39 +dynalite_devices==0.1.40 # homeassistant.components.rainforest_eagle eagle200_reader==0.2.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 998e97dca90..fc4d2fd34a1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -197,7 +197,7 @@ doorbirdpy==2.0.8 dsmr_parser==0.18 # homeassistant.components.dynalite -dynalite_devices==0.1.39 +dynalite_devices==0.1.40 # homeassistant.components.ee_brightbox eebrightbox==0.0.4 diff --git a/tests/components/dynalite/test_bridge.py b/tests/components/dynalite/test_bridge.py index 938bc09f59a..0b093fd5c3e 100644 --- a/tests/components/dynalite/test_bridge.py +++ b/tests/components/dynalite/test_bridge.py @@ -1,7 +1,6 @@ """Test Dynalite bridge.""" from asynctest import CoroutineMock, Mock, patch -from dynalite_devices_lib.const import CONF_ALL from homeassistant.components import dynalite from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -29,7 +28,7 @@ async def test_update_device(hass): async_dispatcher_connect( hass, f"dynalite-update-{host}-{device.unique_id}", specific_func ) - update_device_func(CONF_ALL) + update_device_func() await hass.async_block_till_done() wide_func.assert_called_once() specific_func.assert_not_called()