diff --git a/CODEOWNERS b/CODEOWNERS index 00e05b98778..a4e82847523 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -131,6 +131,7 @@ homeassistant/components/kodi/* @armills homeassistant/components/konnected/* @heythisisnate homeassistant/components/lametric/* @robbiet480 homeassistant/components/launch_library/* @ludeeus +homeassistant/components/lcn/* @alengwenus homeassistant/components/lifx/* @amelchio homeassistant/components/lifx_cloud/* @amelchio homeassistant/components/lifx_legacy/* @amelchio diff --git a/homeassistant/components/lcn/__init__.py b/homeassistant/components/lcn/__init__.py index b2dbccbce7b..77ba00e451d 100644 --- a/homeassistant/components/lcn/__init__.py +++ b/homeassistant/components/lcn/__init__.py @@ -2,7 +2,6 @@ import logging import pypck -from pypck.connection import PchkConnectionManager import voluptuous as vol from homeassistant.components.climate import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP @@ -18,55 +17,13 @@ from .const import ( BINSENSOR_PORTS, CONF_CLIMATES, CONF_CONNECTIONS, CONF_DIM_MODE, CONF_DIMMABLE, CONF_LOCKABLE, CONF_MAX_TEMP, CONF_MIN_TEMP, CONF_MOTOR, CONF_OUTPUT, CONF_SETPOINT, CONF_SK_NUM_TRIES, CONF_SOURCE, - CONF_TRANSITION, DATA_LCN, DEFAULT_NAME, DIM_MODES, DOMAIN, KEYS, - LED_PORTS, LOGICOP_PORTS, MOTOR_PORTS, OUTPUT_PORTS, PATTERN_ADDRESS, - RELAY_PORTS, S0_INPUTS, SETPOINTS, THRESHOLDS, VAR_UNITS, VARIABLES) + CONF_TRANSITION, DATA_LCN, DIM_MODES, DOMAIN, KEYS, LED_PORTS, + LOGICOP_PORTS, MOTOR_PORTS, OUTPUT_PORTS, RELAY_PORTS, S0_INPUTS, + SETPOINTS, THRESHOLDS, VAR_UNITS, VARIABLES) +from .helpers import has_unique_connection_names, is_address _LOGGER = logging.getLogger(__name__) - -def has_unique_connection_names(connections): - """Validate that all connection names are unique. - - Use 'pchk' as default connection_name (or add a numeric suffix if - pchk' is already in use. - """ - for suffix, connection in enumerate(connections): - connection_name = connection.get(CONF_NAME) - if connection_name is None: - if suffix == 0: - connection[CONF_NAME] = DEFAULT_NAME - else: - connection[CONF_NAME] = '{}{:d}'.format(DEFAULT_NAME, suffix) - - schema = vol.Schema(vol.Unique()) - schema([connection.get(CONF_NAME) for connection in connections]) - return connections - - -def is_address(value): - """Validate the given address string. - - Examples for S000M005 at myhome: - myhome.s000.m005 - myhome.s0.m5 - myhome.0.5 ("m" is implicit if missing) - - Examples for s000g011 - myhome.0.g11 - myhome.s0.g11 - """ - matcher = PATTERN_ADDRESS.match(value) - if matcher: - is_group = (matcher.group('type') == 'g') - addr = (int(matcher.group('seg_id')), - int(matcher.group('id')), - is_group) - conn_id = matcher.group('conn_id') - return addr, conn_id - raise vol.error.Invalid('Not a valid address string.') - - BINARY_SENSORS_SCHEMA = vol.Schema({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_ADDRESS): is_address, @@ -153,19 +110,6 @@ CONFIG_SCHEMA = vol.Schema({ }, extra=vol.ALLOW_EXTRA) -def get_connection(connections, connection_id=None): - """Return the connection object from list.""" - if connection_id is None: - connection = connections[0] - else: - for connection in connections: - if connection.connection_id == connection_id: - break - else: - raise ValueError('Unknown connection_id.') - return connection - - async def async_setup(hass, config): """Set up the LCN component.""" hass.data[DATA_LCN] = {} @@ -179,13 +123,14 @@ async def async_setup(hass, config): 'DIM_MODE': pypck.lcn_defs.OutputPortDimMode[ conf_connection[CONF_DIM_MODE]]} - connection = PchkConnectionManager(hass.loop, - conf_connection[CONF_HOST], - conf_connection[CONF_PORT], - conf_connection[CONF_USERNAME], - conf_connection[CONF_PASSWORD], - settings=settings, - connection_id=connection_name) + connection = pypck.connection.PchkConnectionManager( + hass.loop, + conf_connection[CONF_HOST], + conf_connection[CONF_PORT], + conf_connection[CONF_USERNAME], + conf_connection[CONF_PASSWORD], + settings=settings, + connection_id=connection_name) try: # establish connection to PCHK server @@ -218,7 +163,6 @@ class LcnDevice(Entity): def __init__(self, config, address_connection): """Initialize the LCN device.""" - self.pypck = pypck self.config = config self.address_connection = address_connection self._name = config[CONF_NAME] diff --git a/homeassistant/components/lcn/binary_sensor.py b/homeassistant/components/lcn/binary_sensor.py index a59494023bb..7f034b3e1ed 100755 --- a/homeassistant/components/lcn/binary_sensor.py +++ b/homeassistant/components/lcn/binary_sensor.py @@ -4,9 +4,10 @@ import pypck from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.const import CONF_ADDRESS -from . import LcnDevice, get_connection +from . import LcnDevice from .const import ( BINSENSOR_PORTS, CONF_CONNECTIONS, CONF_SOURCE, DATA_LCN, SETPOINTS) +from .helpers import get_connection async def async_setup_platform(hass, hass_config, async_add_entities, @@ -43,7 +44,7 @@ class LcnRegulatorLockSensor(LcnDevice, BinarySensorDevice): super().__init__(config, address_connection) self.setpoint_variable = \ - self.pypck.lcn_defs.Var[config[CONF_SOURCE]] + pypck.lcn_defs.Var[config[CONF_SOURCE]] self._value = None @@ -60,7 +61,7 @@ class LcnRegulatorLockSensor(LcnDevice, BinarySensorDevice): 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.setpoint_variable: return @@ -76,7 +77,7 @@ class LcnBinarySensor(LcnDevice, BinarySensorDevice): super().__init__(config, address_connection) self.bin_sensor_port = \ - self.pypck.lcn_defs.BinSensorPort[config[CONF_SOURCE]] + pypck.lcn_defs.BinSensorPort[config[CONF_SOURCE]] self._value = None @@ -93,7 +94,7 @@ class LcnBinarySensor(LcnDevice, BinarySensorDevice): def input_received(self, input_obj): """Set sensor value when LCN input object (command) is received.""" - if not isinstance(input_obj, self.pypck.inputs.ModStatusBinSensors): + if not isinstance(input_obj, pypck.inputs.ModStatusBinSensors): return self._value = input_obj.get_state(self.bin_sensor_port.value) @@ -107,7 +108,7 @@ class LcnLockKeysSensor(LcnDevice, BinarySensorDevice): """Initialize the LCN sensor.""" super().__init__(config, address_connection) - self.source = self.pypck.lcn_defs.Key[config[CONF_SOURCE]] + self.source = pypck.lcn_defs.Key[config[CONF_SOURCE]] self._value = None async def async_added_to_hass(self): @@ -123,8 +124,8 @@ class LcnLockKeysSensor(LcnDevice, BinarySensorDevice): def input_received(self, input_obj): """Set sensor value when LCN input object (command) is received.""" - if not isinstance(input_obj, self.pypck.inputs.ModStatusKeyLocks) or \ - self.source not in self.pypck.lcn_defs.Key: + if not isinstance(input_obj, pypck.inputs.ModStatusKeyLocks) or \ + self.source not in pypck.lcn_defs.Key: return table_id = ord(self.source.name[0]) - 65 diff --git a/homeassistant/components/lcn/climate.py b/homeassistant/components/lcn/climate.py index 355a9e84c79..67ba6d90c53 100644 --- a/homeassistant/components/lcn/climate.py +++ b/homeassistant/components/lcn/climate.py @@ -5,10 +5,11 @@ from homeassistant.components.climate import ClimateDevice, const from homeassistant.const import ( ATTR_TEMPERATURE, CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT) -from . import LcnDevice, get_connection +from . import LcnDevice from .const import ( CONF_CONNECTIONS, CONF_LOCKABLE, CONF_MAX_TEMP, CONF_MIN_TEMP, CONF_SETPOINT, CONF_SOURCE, DATA_LCN) +from .helpers import get_connection async def async_setup_platform(hass, hass_config, async_add_entities, @@ -37,13 +38,13 @@ class LcnClimate(LcnDevice, ClimateDevice): """Initialize of a LCN climate device.""" super().__init__(config, address_connection) - self.variable = self.pypck.lcn_defs.Var[config[CONF_SOURCE]] - self.setpoint = self.pypck.lcn_defs.Var[config[CONF_SETPOINT]] - self.unit = self.pypck.lcn_defs.VarUnit.parse( + self.variable = pypck.lcn_defs.Var[config[CONF_SOURCE]] + self.setpoint = pypck.lcn_defs.Var[config[CONF_SETPOINT]] + self.unit = pypck.lcn_defs.VarUnit.parse( config[CONF_UNIT_OF_MEASUREMENT]) self.regulator_id = \ - self.pypck.lcn_defs.Var.to_set_point_id(self.setpoint) + pypck.lcn_defs.Var.to_set_point_id(self.setpoint) self.is_lockable = config[CONF_LOCKABLE] self._max_temp = config[CONF_MAX_TEMP] self._min_temp = config[CONF_MIN_TEMP] @@ -125,7 +126,7 @@ class LcnClimate(LcnDevice, ClimateDevice): def input_received(self, input_obj): """Set temperature value when LCN input object is received.""" - if not isinstance(input_obj, self.pypck.inputs.ModStatusVar): + if not isinstance(input_obj, pypck.inputs.ModStatusVar): return if input_obj.get_var() == self.variable: diff --git a/homeassistant/components/lcn/const.py b/homeassistant/components/lcn/const.py index 68818984788..45dc04a491e 100644 --- a/homeassistant/components/lcn/const.py +++ b/homeassistant/components/lcn/const.py @@ -1,7 +1,6 @@ # coding: utf-8 """Constants for the LCN component.""" from itertools import product -import re from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT @@ -9,10 +8,6 @@ DOMAIN = 'lcn' DATA_LCN = 'lcn' DEFAULT_NAME = 'pchk' -# Regex for address validation -PATTERN_ADDRESS = re.compile('^((?P\\w+)\\.)?s?(?P\\d+)' - '\\.(?Pm|g)?(?P\\d+)$') - CONF_CONNECTIONS = 'connections' CONF_SK_NUM_TRIES = 'sk_num_tries' CONF_OUTPUT = 'output' diff --git a/homeassistant/components/lcn/cover.py b/homeassistant/components/lcn/cover.py index d07fa09c189..8b268aa617e 100755 --- a/homeassistant/components/lcn/cover.py +++ b/homeassistant/components/lcn/cover.py @@ -4,8 +4,9 @@ import pypck from homeassistant.components.cover import CoverDevice from homeassistant.const import CONF_ADDRESS -from . import LcnDevice, get_connection +from . import LcnDevice from .const import CONF_CONNECTIONS, CONF_MOTOR, DATA_LCN +from .helpers import get_connection async def async_setup_platform(hass, hass_config, async_add_entities, @@ -34,7 +35,7 @@ class LcnCover(LcnDevice, CoverDevice): """Initialize the LCN cover.""" super().__init__(config, address_connection) - self.motor = self.pypck.lcn_defs.MotorPort[config[CONF_MOTOR]] + self.motor = pypck.lcn_defs.MotorPort[config[CONF_MOTOR]] self.motor_port_onoff = self.motor.value * 2 self.motor_port_updown = self.motor_port_onoff + 1 @@ -54,30 +55,30 @@ class LcnCover(LcnDevice, CoverDevice): async def async_close_cover(self, **kwargs): """Close the cover.""" self._closed = True - states = [self.pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 - states[self.motor.value] = self.pypck.lcn_defs.MotorStateModifier.DOWN + states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 + states[self.motor.value] = pypck.lcn_defs.MotorStateModifier.DOWN self.address_connection.control_motors(states) await self.async_update_ha_state() async def async_open_cover(self, **kwargs): """Open the cover.""" self._closed = False - states = [self.pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 - states[self.motor.value] = self.pypck.lcn_defs.MotorStateModifier.UP + states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 + states[self.motor.value] = pypck.lcn_defs.MotorStateModifier.UP self.address_connection.control_motors(states) await self.async_update_ha_state() async def async_stop_cover(self, **kwargs): """Stop the cover.""" self._closed = None - states = [self.pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 - states[self.motor.value] = self.pypck.lcn_defs.MotorStateModifier.STOP + states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4 + states[self.motor.value] = pypck.lcn_defs.MotorStateModifier.STOP self.address_connection.control_motors(states) await self.async_update_ha_state() def input_received(self, input_obj): """Set cover states 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 states = input_obj.states # list of boolean values (relay on/off) diff --git a/homeassistant/components/lcn/helpers.py b/homeassistant/components/lcn/helpers.py new file mode 100644 index 00000000000..701b6e2436e --- /dev/null +++ b/homeassistant/components/lcn/helpers.py @@ -0,0 +1,67 @@ +"""Helpers for LCN component.""" +import re + +import voluptuous as vol + +from homeassistant.const import CONF_NAME + +from .const import DEFAULT_NAME + +# Regex for address validation +PATTERN_ADDRESS = re.compile('^((?P\\w+)\\.)?s?(?P\\d+)' + '\\.(?Pm|g)?(?P\\d+)$') + + +def get_connection(connections, connection_id=None): + """Return the connection object from list.""" + if connection_id is None: + connection = connections[0] + else: + for connection in connections: + if connection.connection_id == connection_id: + break + else: + raise ValueError('Unknown connection_id.') + return connection + + +def has_unique_connection_names(connections): + """Validate that all connection names are unique. + + Use 'pchk' as default connection_name (or add a numeric suffix if + pchk' is already in use. + """ + for suffix, connection in enumerate(connections): + connection_name = connection.get(CONF_NAME) + if connection_name is None: + if suffix == 0: + connection[CONF_NAME] = DEFAULT_NAME + else: + connection[CONF_NAME] = '{}{:d}'.format(DEFAULT_NAME, suffix) + + schema = vol.Schema(vol.Unique()) + schema([connection.get(CONF_NAME) for connection in connections]) + return connections + + +def is_address(value): + """Validate the given address string. + + Examples for S000M005 at myhome: + myhome.s000.m005 + myhome.s0.m5 + myhome.0.5 ("m" is implicit if missing) + + Examples for s000g011 + myhome.0.g11 + myhome.s0.g11 + """ + matcher = PATTERN_ADDRESS.match(value) + if matcher: + is_group = (matcher.group('type') == 'g') + addr = (int(matcher.group('seg_id')), + int(matcher.group('id')), + is_group) + conn_id = matcher.group('conn_id') + return addr, conn_id + raise vol.error.Invalid('Not a valid address string.') diff --git a/homeassistant/components/lcn/light.py b/homeassistant/components/lcn/light.py index 49cdff5de49..28d85d6d45a 100644 --- a/homeassistant/components/lcn/light.py +++ b/homeassistant/components/lcn/light.py @@ -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) diff --git a/homeassistant/components/lcn/manifest.json b/homeassistant/components/lcn/manifest.json index bbf2746c067..5f0d1052741 100644 --- a/homeassistant/components/lcn/manifest.json +++ b/homeassistant/components/lcn/manifest.json @@ -3,8 +3,10 @@ "name": "Lcn", "documentation": "https://www.home-assistant.io/components/lcn", "requirements": [ - "pypck==0.5.9" + "pypck==0.6.0" ], "dependencies": [], - "codeowners": [] + "codeowners": [ + "@alengwenus" + ] } diff --git a/homeassistant/components/lcn/sensor.py b/homeassistant/components/lcn/sensor.py index 38b17c80793..91d2b916cca 100755 --- a/homeassistant/components/lcn/sensor.py +++ b/homeassistant/components/lcn/sensor.py @@ -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() diff --git a/homeassistant/components/lcn/switch.py b/homeassistant/components/lcn/switch.py index e5a8484e271..1e86609c38c 100755 --- a/homeassistant/components/lcn/switch.py +++ b/homeassistant/components/lcn/switch.py @@ -4,8 +4,9 @@ import pypck from homeassistant.components.switch import SwitchDevice from homeassistant.const import CONF_ADDRESS -from . import LcnDevice, get_connection +from . import LcnDevice from .const import CONF_CONNECTIONS, CONF_OUTPUT, DATA_LCN, OUTPUT_PORTS +from .helpers import get_connection async def async_setup_platform(hass, hass_config, async_add_entities, @@ -39,7 +40,7 @@ class LcnOutputSwitch(LcnDevice, SwitchDevice): """Initialize the LCN switch.""" 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._is_on = None @@ -68,7 +69,7 @@ class LcnOutputSwitch(LcnDevice, SwitchDevice): def input_received(self, input_obj): """Set switch 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 @@ -83,7 +84,7 @@ class LcnRelaySwitch(LcnDevice, SwitchDevice): """Initialize the LCN switch.""" 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 @@ -102,8 +103,8 @@ class LcnRelaySwitch(LcnDevice, SwitchDevice): """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() @@ -111,14 +112,14 @@ class LcnRelaySwitch(LcnDevice, SwitchDevice): """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 switch 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) diff --git a/requirements_all.txt b/requirements_all.txt index dbaa52d6baf..3eebc5530a7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1259,7 +1259,7 @@ pyowlet==1.0.2 pyowm==2.10.0 # homeassistant.components.lcn -pypck==0.5.9 +pypck==0.6.0 # homeassistant.components.pjlink pypjlink2==1.2.0