mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Refactoring of LCN component (#23824)
* Moved helper functions to const.py * Removed pypck attribute from LcnDevice * Bump to pypck==0.6.0 * Added myself as a codeowner * Moved helper functions to helpers.py
This commit is contained in:
committed by
Martin Hjelmare
parent
9d7aa8f05d
commit
c928f82cbf
@@ -6,10 +6,11 @@ from homeassistant.components.light import (
|
||||
Light)
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
|
||||
from . import LcnDevice, get_connection
|
||||
from . import LcnDevice
|
||||
from .const import (
|
||||
CONF_CONNECTIONS, CONF_DIMMABLE, CONF_OUTPUT, CONF_TRANSITION, DATA_LCN,
|
||||
OUTPUT_PORTS)
|
||||
from .helpers import get_connection
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
@@ -43,9 +44,9 @@ class LcnOutputLight(LcnDevice, Light):
|
||||
"""Initialize the LCN light."""
|
||||
super().__init__(config, address_connection)
|
||||
|
||||
self.output = self.pypck.lcn_defs.OutputPort[config[CONF_OUTPUT]]
|
||||
self.output = pypck.lcn_defs.OutputPort[config[CONF_OUTPUT]]
|
||||
|
||||
self._transition = self.pypck.lcn_defs.time_to_ramp_value(
|
||||
self._transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
config[CONF_TRANSITION])
|
||||
self.dimmable = config[CONF_DIMMABLE]
|
||||
|
||||
@@ -86,7 +87,7 @@ class LcnOutputLight(LcnDevice, Light):
|
||||
else:
|
||||
percent = 100
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
transition = self.pypck.lcn_defs.time_to_ramp_value(
|
||||
transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
kwargs[ATTR_TRANSITION] * 1000)
|
||||
else:
|
||||
transition = self._transition
|
||||
@@ -99,7 +100,7 @@ class LcnOutputLight(LcnDevice, Light):
|
||||
"""Turn the entity off."""
|
||||
self._is_on = False
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
transition = self.pypck.lcn_defs.time_to_ramp_value(
|
||||
transition = pypck.lcn_defs.time_to_ramp_value(
|
||||
kwargs[ATTR_TRANSITION] * 1000)
|
||||
else:
|
||||
transition = self._transition
|
||||
@@ -111,7 +112,7 @@ 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, self.pypck.inputs.ModStatusOutput) or \
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusOutput) or \
|
||||
input_obj.get_output_id() != self.output.value:
|
||||
return
|
||||
|
||||
@@ -130,7 +131,7 @@ class LcnRelayLight(LcnDevice, Light):
|
||||
"""Initialize the LCN light."""
|
||||
super().__init__(config, address_connection)
|
||||
|
||||
self.output = self.pypck.lcn_defs.RelayPort[config[CONF_OUTPUT]]
|
||||
self.output = pypck.lcn_defs.RelayPort[config[CONF_OUTPUT]]
|
||||
|
||||
self._is_on = None
|
||||
|
||||
@@ -149,8 +150,8 @@ class LcnRelayLight(LcnDevice, Light):
|
||||
"""Turn the entity on."""
|
||||
self._is_on = True
|
||||
|
||||
states = [self.pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
|
||||
states[self.output.value] = self.pypck.lcn_defs.RelayStateModifier.ON
|
||||
states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
|
||||
states[self.output.value] = pypck.lcn_defs.RelayStateModifier.ON
|
||||
self.address_connection.control_relays(states)
|
||||
|
||||
await self.async_update_ha_state()
|
||||
@@ -159,15 +160,15 @@ class LcnRelayLight(LcnDevice, Light):
|
||||
"""Turn the entity off."""
|
||||
self._is_on = False
|
||||
|
||||
states = [self.pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
|
||||
states[self.output.value] = self.pypck.lcn_defs.RelayStateModifier.OFF
|
||||
states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
|
||||
states[self.output.value] = pypck.lcn_defs.RelayStateModifier.OFF
|
||||
self.address_connection.control_relays(states)
|
||||
|
||||
await self.async_update_ha_state()
|
||||
|
||||
def input_received(self, input_obj):
|
||||
"""Set light state when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj, self.pypck.inputs.ModStatusRelays):
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusRelays):
|
||||
return
|
||||
|
||||
self._is_on = input_obj.get_state(self.output.value)
|
||||
|
||||
Reference in New Issue
Block a user