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:
parent
9d7aa8f05d
commit
c928f82cbf
12 changed files with 144 additions and 129 deletions
|
@ -3,10 +3,11 @@ import pypck
|
|||
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT
|
||||
|
||||
from . import LcnDevice, get_connection
|
||||
from . import LcnDevice
|
||||
from .const import (
|
||||
CONF_CONNECTIONS, CONF_SOURCE, DATA_LCN, LED_PORTS, S0_INPUTS, SETPOINTS,
|
||||
THRESHOLDS, VARIABLES)
|
||||
from .helpers import get_connection
|
||||
|
||||
|
||||
async def async_setup_platform(hass, hass_config, async_add_entities,
|
||||
|
@ -41,8 +42,8 @@ class LcnVariableSensor(LcnDevice):
|
|||
"""Initialize the LCN sensor."""
|
||||
super().__init__(config, address_connection)
|
||||
|
||||
self.variable = self.pypck.lcn_defs.Var[config[CONF_SOURCE]]
|
||||
self.unit = self.pypck.lcn_defs.VarUnit.parse(
|
||||
self.variable = pypck.lcn_defs.Var[config[CONF_SOURCE]]
|
||||
self.unit = pypck.lcn_defs.VarUnit.parse(
|
||||
config[CONF_UNIT_OF_MEASUREMENT])
|
||||
|
||||
self._value = None
|
||||
|
@ -65,7 +66,7 @@ class LcnVariableSensor(LcnDevice):
|
|||
|
||||
def input_received(self, input_obj):
|
||||
"""Set sensor value when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj, self.pypck.inputs.ModStatusVar) or \
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusVar) or \
|
||||
input_obj.get_var() != self.variable:
|
||||
return
|
||||
|
||||
|
@ -81,9 +82,9 @@ class LcnLedLogicSensor(LcnDevice):
|
|||
super().__init__(config, address_connection)
|
||||
|
||||
if config[CONF_SOURCE] in LED_PORTS:
|
||||
self.source = self.pypck.lcn_defs.LedPort[config[CONF_SOURCE]]
|
||||
self.source = pypck.lcn_defs.LedPort[config[CONF_SOURCE]]
|
||||
else:
|
||||
self.source = self.pypck.lcn_defs.LogicOpPort[config[CONF_SOURCE]]
|
||||
self.source = pypck.lcn_defs.LogicOpPort[config[CONF_SOURCE]]
|
||||
|
||||
self._value = None
|
||||
|
||||
|
@ -101,13 +102,13 @@ class LcnLedLogicSensor(LcnDevice):
|
|||
def input_received(self, input_obj):
|
||||
"""Set sensor value when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj,
|
||||
self.pypck.inputs.ModStatusLedsAndLogicOps):
|
||||
pypck.inputs.ModStatusLedsAndLogicOps):
|
||||
return
|
||||
|
||||
if self.source in self.pypck.lcn_defs.LedPort:
|
||||
if self.source in pypck.lcn_defs.LedPort:
|
||||
self._value = input_obj.get_led_state(
|
||||
self.source.value).name.lower()
|
||||
elif self.source in self.pypck.lcn_defs.LogicOpPort:
|
||||
elif self.source in pypck.lcn_defs.LogicOpPort:
|
||||
self._value = input_obj.get_logic_op_state(
|
||||
self.source.value).name.lower()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue