Refactor LCN integration (#40665)

* Moved configuration schemes to schemes.py

* Renamed LcnDevice to LcnEntity. Renamed address_connection to device_connection.

* Rename schemes.py to schemas.py
This commit is contained in:
Andre Lengwenus 2020-12-05 12:57:49 +01:00 committed by GitHub
parent bc83e30761
commit 378424b2c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 286 additions and 266 deletions

View file

@ -4,7 +4,7 @@ import pypck
from homeassistant.components.switch import SwitchEntity
from homeassistant.const import CONF_ADDRESS
from . import LcnDevice
from . import LcnEntity
from .const import CONF_CONNECTIONS, CONF_OUTPUT, DATA_LCN, OUTPUT_PORTS
from .helpers import get_connection
@ -36,12 +36,12 @@ async def async_setup_platform(
async_add_entities(devices)
class LcnOutputSwitch(LcnDevice, SwitchEntity):
class LcnOutputSwitch(LcnEntity, SwitchEntity):
"""Representation of a LCN switch for output ports."""
def __init__(self, config, address_connection):
def __init__(self, config, device_connection):
"""Initialize the LCN switch."""
super().__init__(config, address_connection)
super().__init__(config, device_connection)
self.output = pypck.lcn_defs.OutputPort[config[CONF_OUTPUT]]
@ -50,7 +50,7 @@ class LcnOutputSwitch(LcnDevice, SwitchEntity):
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.device_connection.activate_status_request_handler(self.output)
@property
def is_on(self):
@ -59,14 +59,14 @@ class LcnOutputSwitch(LcnDevice, SwitchEntity):
async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
if not await self.address_connection.dim_output(self.output.value, 100, 0):
if not await self.device_connection.dim_output(self.output.value, 100, 0):
return
self._is_on = True
self.async_write_ha_state()
async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
if not await self.address_connection.dim_output(self.output.value, 0, 0):
if not await self.device_connection.dim_output(self.output.value, 0, 0):
return
self._is_on = False
self.async_write_ha_state()
@ -83,12 +83,12 @@ class LcnOutputSwitch(LcnDevice, SwitchEntity):
self.async_write_ha_state()
class LcnRelaySwitch(LcnDevice, SwitchEntity):
class LcnRelaySwitch(LcnEntity, SwitchEntity):
"""Representation of a LCN switch for relay ports."""
def __init__(self, config, address_connection):
def __init__(self, config, device_connection):
"""Initialize the LCN switch."""
super().__init__(config, address_connection)
super().__init__(config, device_connection)
self.output = pypck.lcn_defs.RelayPort[config[CONF_OUTPUT]]
@ -97,7 +97,7 @@ class LcnRelaySwitch(LcnDevice, SwitchEntity):
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.device_connection.activate_status_request_handler(self.output)
@property
def is_on(self):
@ -108,7 +108,7 @@ class LcnRelaySwitch(LcnDevice, SwitchEntity):
"""Turn the entity on."""
states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
states[self.output.value] = pypck.lcn_defs.RelayStateModifier.ON
if not await self.address_connection.control_relays(states):
if not await self.device_connection.control_relays(states):
return
self._is_on = True
self.async_write_ha_state()
@ -118,7 +118,7 @@ class LcnRelaySwitch(LcnDevice, SwitchEntity):
states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
states[self.output.value] = pypck.lcn_defs.RelayStateModifier.OFF
if not await self.address_connection.control_relays(states):
if not await self.device_connection.control_relays(states):
return
self._is_on = False
self.async_write_ha_state()