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

@ -5,7 +5,7 @@ import pypck
from homeassistant.components.climate import ClimateEntity, const
from homeassistant.const import ATTR_TEMPERATURE, CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT
from . import LcnDevice
from . import LcnEntity
from .const import (
CONF_CONNECTIONS,
CONF_LOCKABLE,
@ -40,12 +40,12 @@ async def async_setup_platform(
async_add_entities(devices)
class LcnClimate(LcnDevice, ClimateEntity):
class LcnClimate(LcnEntity, ClimateEntity):
"""Representation of a LCN climate device."""
def __init__(self, config, address_connection):
def __init__(self, config, device_connection):
"""Initialize of a LCN climate device."""
super().__init__(config, address_connection)
super().__init__(config, device_connection)
self.variable = pypck.lcn_defs.Var[config[CONF_SOURCE]]
self.setpoint = pypck.lcn_defs.Var[config[CONF_SETPOINT]]
@ -63,8 +63,8 @@ class LcnClimate(LcnDevice, ClimateEntity):
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.variable)
await self.address_connection.activate_status_request_handler(self.setpoint)
await self.device_connection.activate_status_request_handler(self.variable)
await self.device_connection.activate_status_request_handler(self.setpoint)
@property
def supported_features(self):
@ -120,16 +120,14 @@ class LcnClimate(LcnDevice, ClimateEntity):
async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
if hvac_mode == const.HVAC_MODE_HEAT:
if not await self.address_connection.lock_regulator(
if not await self.device_connection.lock_regulator(
self.regulator_id, False
):
return
self._is_on = True
self.async_write_ha_state()
elif hvac_mode == const.HVAC_MODE_OFF:
if not await self.address_connection.lock_regulator(
self.regulator_id, True
):
if not await self.device_connection.lock_regulator(self.regulator_id, True):
return
self._is_on = False
self._target_temperature = None
@ -141,7 +139,7 @@ class LcnClimate(LcnDevice, ClimateEntity):
if temperature is None:
return
if not await self.address_connection.var_abs(
if not await self.device_connection.var_abs(
self.setpoint, temperature, self.unit
):
return