* refactoring for multi platform * adopted test_bridge to refactoring * refactoring tests for multi-platform additional coverage in config and init * comment for clarity * more specific imports from lib * library version bump * removed async_update * changed parameter order to start with hass * removed pylint disable * unsubscribe from signal dispatcher inherit from Entity * use device.unique_id * changed hass_obj to hass * added test for remove entity bug fix from the test * removed the polling try_connect. hate polling... it is now part of the async_setup() significantly makes the code clearer and simplifies the tests * removed leftover debug logs in the library * changed tests to get the entry_id from hass * changed place to assign hass.data only after success * fixes for test_init * removed assert * removed device_info * removed bridge internal from common * modified test_bridge to work without the bridge directly * removed bridge from test_existing_update * changed update to not use bridge internals * dyn_bridge fixture no longer used - removed
44 lines
1.3 KiB
Python
Executable file
44 lines
1.3 KiB
Python
Executable file
"""Support for Dynalite channels as lights."""
|
|
from homeassistant.components.light import SUPPORT_BRIGHTNESS, Light
|
|
from homeassistant.core import callback
|
|
|
|
from .dynalitebase import DynaliteBase, async_setup_entry_base
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Record the async_add_entities function to add them later when received from Dynalite."""
|
|
|
|
@callback
|
|
def light_from_device(device, bridge):
|
|
return DynaliteLight(device, bridge)
|
|
|
|
async_setup_entry_base(
|
|
hass, config_entry, async_add_entities, "light", light_from_device
|
|
)
|
|
|
|
|
|
class DynaliteLight(DynaliteBase, Light):
|
|
"""Representation of a Dynalite Channel as a Home Assistant Light."""
|
|
|
|
@property
|
|
def brightness(self):
|
|
"""Return the brightness of this light between 0..255."""
|
|
return self._device.brightness
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return true if device is on."""
|
|
return self._device.is_on
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
"""Turn the light on."""
|
|
await self._device.async_turn_on(**kwargs)
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
"""Turn the light off."""
|
|
await self._device.async_turn_off(**kwargs)
|
|
|
|
@property
|
|
def supported_features(self):
|
|
"""Flag supported features."""
|
|
return SUPPORT_BRIGHTNESS
|