Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -2,19 +2,29 @@
|
|||
import pypck
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_TRANSITION, SUPPORT_BRIGHTNESS, SUPPORT_TRANSITION,
|
||||
Light)
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_TRANSITION,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_TRANSITION,
|
||||
Light,
|
||||
)
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
|
||||
from . import LcnDevice
|
||||
from .const import (
|
||||
CONF_CONNECTIONS, CONF_DIMMABLE, CONF_OUTPUT, CONF_TRANSITION, DATA_LCN,
|
||||
OUTPUT_PORTS)
|
||||
CONF_CONNECTIONS,
|
||||
CONF_DIMMABLE,
|
||||
CONF_OUTPUT,
|
||||
CONF_TRANSITION,
|
||||
DATA_LCN,
|
||||
OUTPUT_PORTS,
|
||||
)
|
||||
from .helpers import get_connection
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass, hass_config, async_add_entities, discovery_info=None):
|
||||
hass, hass_config, async_add_entities, discovery_info=None
|
||||
):
|
||||
"""Set up the LCN light platform."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -46,8 +56,7 @@ class LcnOutputLight(LcnDevice, Light):
|
|||
|
||||
self.output = pypck.lcn_defs.OutputPort[config[CONF_OUTPUT]]
|
||||
|
||||
self._transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
config[CONF_TRANSITION])
|
||||
self._transition = pypck.lcn_defs.time_to_ramp_value(config[CONF_TRANSITION])
|
||||
self.dimmable = config[CONF_DIMMABLE]
|
||||
|
||||
self._brightness = 255
|
||||
|
@ -57,8 +66,7 @@ class LcnOutputLight(LcnDevice, Light):
|
|||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
await self.address_connection.activate_status_request_handler(
|
||||
self.output)
|
||||
await self.address_connection.activate_status_request_handler(self.output)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
@ -83,17 +91,17 @@ class LcnOutputLight(LcnDevice, Light):
|
|||
self._is_on = True
|
||||
self._is_dimming_to_zero = False
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
percent = int(kwargs[ATTR_BRIGHTNESS] / 255. * 100)
|
||||
percent = int(kwargs[ATTR_BRIGHTNESS] / 255.0 * 100)
|
||||
else:
|
||||
percent = 100
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
kwargs[ATTR_TRANSITION] * 1000)
|
||||
kwargs[ATTR_TRANSITION] * 1000
|
||||
)
|
||||
else:
|
||||
transition = self._transition
|
||||
|
||||
self.address_connection.dim_output(self.output.value, percent,
|
||||
transition)
|
||||
self.address_connection.dim_output(self.output.value, percent, transition)
|
||||
await self.async_update_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
|
@ -101,7 +109,8 @@ class LcnOutputLight(LcnDevice, Light):
|
|||
self._is_on = False
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
kwargs[ATTR_TRANSITION] * 1000)
|
||||
kwargs[ATTR_TRANSITION] * 1000
|
||||
)
|
||||
else:
|
||||
transition = self._transition
|
||||
|
||||
|
@ -112,11 +121,13 @@ class LcnOutputLight(LcnDevice, Light):
|
|||
|
||||
def input_received(self, input_obj):
|
||||
"""Set light state when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusOutput) or \
|
||||
input_obj.get_output_id() != self.output.value:
|
||||
if (
|
||||
not isinstance(input_obj, pypck.inputs.ModStatusOutput)
|
||||
or input_obj.get_output_id() != self.output.value
|
||||
):
|
||||
return
|
||||
|
||||
self._brightness = int(input_obj.get_percent() / 100.*255)
|
||||
self._brightness = int(input_obj.get_percent() / 100.0 * 255)
|
||||
if self.brightness == 0:
|
||||
self._is_dimming_to_zero = False
|
||||
if not self._is_dimming_to_zero:
|
||||
|
@ -138,8 +149,7 @@ class LcnRelayLight(LcnDevice, Light):
|
|||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
await self.address_connection.activate_status_request_handler(
|
||||
self.output)
|
||||
await self.address_connection.activate_status_request_handler(self.output)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue