core/homeassistant/components/dynalite/bridge.py

120 lines
4.6 KiB
Python
Raw Normal View History

"""Code to handle a Dynalite bridge."""
from typing import Any, Callable, Dict, List, Optional
from dynalite_devices_lib.dynalite_devices import (
CONF_AREA as dyn_CONF_AREA,
CONF_PRESET as dyn_CONF_PRESET,
NOTIFICATION_PACKET,
NOTIFICATION_PRESET,
DynaliteBaseDevice,
DynaliteDevices,
DynaliteNotification,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant, callback
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import (
ATTR_AREA,
ATTR_HOST,
ATTR_PACKET,
ATTR_PRESET,
ENTITY_PLATFORMS,
LOGGER,
)
from .convert_config import convert_config
class DynaliteBridge:
"""Manages a single Dynalite bridge."""
def __init__(self, hass: HomeAssistant, config: Dict[str, Any]) -> None:
"""Initialize the system based on host parameter."""
self.hass = hass
self.area = {}
self.async_add_devices = {}
self.waiting_devices = {}
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
self.host = config[CONF_HOST]
# Configure the dynalite devices
self.dynalite_devices = DynaliteDevices(
new_device_func=self.add_devices_when_registered,
update_device_func=self.update_device,
notification_func=self.handle_notification,
)
self.dynalite_devices.configure(convert_config(config))
async def async_setup(self) -> bool:
"""Set up a Dynalite bridge."""
# Configure the dynalite devices
LOGGER.debug("Setting up bridge - host %s", self.host)
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
return await self.dynalite_devices.async_setup()
def reload_config(self, config: Dict[str, Any]) -> None:
"""Reconfigure a bridge when config changes."""
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
self.dynalite_devices.configure(convert_config(config))
def update_signal(self, device: Optional[DynaliteBaseDevice] = None) -> str:
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
"""Create signal to use to trigger entity update."""
if device:
signal = f"dynalite-update-{self.host}-{device.unique_id}"
else:
signal = f"dynalite-update-{self.host}"
return signal
@callback
def update_device(self, device: Optional[DynaliteBaseDevice] = None) -> None:
"""Call when a device or all devices should be updated."""
if not device:
# This is used to signal connection or disconnection, so all devices may become available or not.
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
log_string = (
"Connected" if self.dynalite_devices.connected else "Disconnected"
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
)
LOGGER.info("%s to dynalite host", log_string)
async_dispatcher_send(self.hass, self.update_signal())
else:
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
async_dispatcher_send(self.hass, self.update_signal(device))
@callback
def handle_notification(self, notification: DynaliteNotification) -> None:
"""Handle a notification from the platform and issue events."""
if notification.notification == NOTIFICATION_PACKET:
self.hass.bus.async_fire(
"dynalite_packet",
{
ATTR_HOST: self.host,
ATTR_PACKET: notification.data[NOTIFICATION_PACKET],
},
)
if notification.notification == NOTIFICATION_PRESET:
self.hass.bus.async_fire(
"dynalite_preset",
{
ATTR_HOST: self.host,
ATTR_AREA: notification.data[dyn_CONF_AREA],
ATTR_PRESET: notification.data[dyn_CONF_PRESET],
},
)
@callback
def register_add_devices(self, platform: str, async_add_devices: Callable) -> None:
"""Add an async_add_entities for a category."""
self.async_add_devices[platform] = async_add_devices
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:
Enhance Dynalite Integration after review (#31760) * fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-02-21 22:29:59 +00:00
"""Add the devices to HA if the add devices callback was registered, otherwise queue until it is."""
for platform in ENTITY_PLATFORMS:
platform_devices = [
device for device in devices if device.category == platform
]
if platform in self.async_add_devices:
self.async_add_devices[platform](platform_devices)
else: # handle it later when it is registered
if platform not in self.waiting_devices:
self.waiting_devices[platform] = []
self.waiting_devices[platform].extend(platform_devices)