Update dynalite library and minor changes (#34618)

This commit is contained in:
Ziv 2020-04-24 19:30:45 +03:00 committed by GitHub
parent 71617e8e8b
commit 4afa2a2651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 22 deletions

View file

@ -117,7 +117,7 @@ AREA_DATA_SCHEMA = vol.Schema(
vol.All( vol.All(
{ {
vol.Required(CONF_NAME): cv.string, 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_FADE): vol.Coerce(float),
vol.Optional(CONF_NO_DEFAULT): cv.boolean, vol.Optional(CONF_NO_DEFAULT): cv.boolean,
vol.Optional(CONF_CHANNEL): CHANNEL_SCHEMA, vol.Optional(CONF_CHANNEL): CHANNEL_SCHEMA,

View file

@ -1,21 +1,16 @@
"""Code to handle a Dynalite bridge.""" """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.const import CONF_HOST
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_send 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 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: class DynaliteBridge:
"""Manages a single Dynalite bridge.""" """Manages a single Dynalite bridge."""
@ -45,7 +40,7 @@ class DynaliteBridge:
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config) LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
self.dynalite_devices.configure(convert_config(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.""" """Create signal to use to trigger entity update."""
if device: if device:
signal = f"dynalite-update-{self.host}-{device.unique_id}" signal = f"dynalite-update-{self.host}-{device.unique_id}"
@ -54,9 +49,9 @@ class DynaliteBridge:
return signal return signal
@callback @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.""" """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. # This is used to signal connection or disconnection, so all devices may become available or not.
log_string = ( log_string = (
"Connected" if self.dynalite_devices.connected else "Disconnected" "Connected" if self.dynalite_devices.connected else "Disconnected"
@ -73,7 +68,7 @@ class DynaliteBridge:
if platform in self.waiting_devices: if platform in self.waiting_devices:
self.async_add_devices[platform](self.waiting_devices[platform]) 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.""" """Add the devices to HA if the add devices callback was registered, otherwise queue until it is."""
for platform in ENTITY_PLATFORMS: for platform in ENTITY_PLATFORMS:
platform_devices = [ platform_devices = [

View file

@ -14,7 +14,6 @@ CONF_ACTIVE = "active"
ACTIVE_INIT = "init" ACTIVE_INIT = "init"
ACTIVE_OFF = "off" ACTIVE_OFF = "off"
ACTIVE_ON = "on" ACTIVE_ON = "on"
CONF_ALL = "ALL"
CONF_AREA = "area" CONF_AREA = "area"
CONF_AUTO_DISCOVER = "autodiscover" CONF_AUTO_DISCOVER = "autodiscover"
CONF_BRIDGES = "bridges" CONF_BRIDGES = "bridges"

View file

@ -34,9 +34,9 @@ from .const import (
CONF_MAP = { CONF_MAP = {
CONF_ACTIVE: dyn_const.CONF_ACTIVE, CONF_ACTIVE: dyn_const.CONF_ACTIVE,
ACTIVE_INIT: dyn_const.CONF_ACTIVE_INIT, ACTIVE_INIT: dyn_const.ACTIVE_INIT,
ACTIVE_OFF: dyn_const.CONF_ACTIVE_OFF, ACTIVE_OFF: dyn_const.ACTIVE_OFF,
ACTIVE_ON: dyn_const.CONF_ACTIVE_ON, ACTIVE_ON: dyn_const.ACTIVE_ON,
CONF_AREA: dyn_const.CONF_AREA, CONF_AREA: dyn_const.CONF_AREA,
CONF_AUTO_DISCOVER: dyn_const.CONF_AUTO_DISCOVER, CONF_AUTO_DISCOVER: dyn_const.CONF_AUTO_DISCOVER,
CONF_CHANNEL: dyn_const.CONF_CHANNEL, CONF_CHANNEL: dyn_const.CONF_CHANNEL,

View file

@ -4,5 +4,5 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/dynalite", "documentation": "https://www.home-assistant.io/integrations/dynalite",
"codeowners": ["@ziv1234"], "codeowners": ["@ziv1234"],
"requirements": ["dynalite_devices==0.1.39"] "requirements": ["dynalite_devices==0.1.40"]
} }

View file

@ -481,7 +481,7 @@ dsmr_parser==0.18
dweepy==0.3.0 dweepy==0.3.0
# homeassistant.components.dynalite # homeassistant.components.dynalite
dynalite_devices==0.1.39 dynalite_devices==0.1.40
# homeassistant.components.rainforest_eagle # homeassistant.components.rainforest_eagle
eagle200_reader==0.2.4 eagle200_reader==0.2.4

View file

@ -197,7 +197,7 @@ doorbirdpy==2.0.8
dsmr_parser==0.18 dsmr_parser==0.18
# homeassistant.components.dynalite # homeassistant.components.dynalite
dynalite_devices==0.1.39 dynalite_devices==0.1.40
# homeassistant.components.ee_brightbox # homeassistant.components.ee_brightbox
eebrightbox==0.0.4 eebrightbox==0.0.4

View file

@ -1,7 +1,6 @@
"""Test Dynalite bridge.""" """Test Dynalite bridge."""
from asynctest import CoroutineMock, Mock, patch from asynctest import CoroutineMock, Mock, patch
from dynalite_devices_lib.const import CONF_ALL
from homeassistant.components import dynalite from homeassistant.components import dynalite
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -29,7 +28,7 @@ async def test_update_device(hass):
async_dispatcher_connect( async_dispatcher_connect(
hass, f"dynalite-update-{host}-{device.unique_id}", specific_func hass, f"dynalite-update-{host}-{device.unique_id}", specific_func
) )
update_device_func(CONF_ALL) update_device_func()
await hass.async_block_till_done() await hass.async_block_till_done()
wide_func.assert_called_once() wide_func.assert_called_once()
specific_func.assert_not_called() specific_func.assert_not_called()