Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -5,13 +5,21 @@ from homeassistant.const import CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT
|
|||
|
||||
from . import LcnDevice
|
||||
from .const import (
|
||||
CONF_CONNECTIONS, CONF_SOURCE, DATA_LCN, LED_PORTS, S0_INPUTS, SETPOINTS,
|
||||
THRESHOLDS, VARIABLES)
|
||||
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,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass, hass_config, async_add_entities, discovery_info=None
|
||||
):
|
||||
"""Set up the LCN sensor platform."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -24,8 +32,7 @@ async def async_setup_platform(hass, hass_config, async_add_entities,
|
|||
connection = get_connection(connections, connection_id)
|
||||
address_connection = connection.get_address_conn(addr)
|
||||
|
||||
if config[CONF_SOURCE] in VARIABLES + SETPOINTS + THRESHOLDS + \
|
||||
S0_INPUTS:
|
||||
if config[CONF_SOURCE] in VARIABLES + SETPOINTS + THRESHOLDS + S0_INPUTS:
|
||||
device = LcnVariableSensor(config, address_connection)
|
||||
else: # in LED_PORTS + LOGICOP_PORTS
|
||||
device = LcnLedLogicSensor(config, address_connection)
|
||||
|
@ -43,16 +50,14 @@ class LcnVariableSensor(LcnDevice):
|
|||
super().__init__(config, address_connection)
|
||||
|
||||
self.variable = pypck.lcn_defs.Var[config[CONF_SOURCE]]
|
||||
self.unit = pypck.lcn_defs.VarUnit.parse(
|
||||
config[CONF_UNIT_OF_MEASUREMENT])
|
||||
self.unit = pypck.lcn_defs.VarUnit.parse(config[CONF_UNIT_OF_MEASUREMENT])
|
||||
|
||||
self._value = None
|
||||
|
||||
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.variable)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -66,11 +71,13 @@ class LcnVariableSensor(LcnDevice):
|
|||
|
||||
def input_received(self, input_obj):
|
||||
"""Set sensor value when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusVar) or \
|
||||
input_obj.get_var() != self.variable:
|
||||
if (
|
||||
not isinstance(input_obj, pypck.inputs.ModStatusVar)
|
||||
or input_obj.get_var() != self.variable
|
||||
):
|
||||
return
|
||||
|
||||
self._value = (input_obj.get_value().to_var_unit(self.unit))
|
||||
self._value = input_obj.get_value().to_var_unit(self.unit)
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
||||
|
@ -91,8 +98,7 @@ class LcnLedLogicSensor(LcnDevice):
|
|||
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.source)
|
||||
await self.address_connection.activate_status_request_handler(self.source)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -101,15 +107,12 @@ class LcnLedLogicSensor(LcnDevice):
|
|||
|
||||
def input_received(self, input_obj):
|
||||
"""Set sensor value when LCN input object (command) is received."""
|
||||
if not isinstance(input_obj,
|
||||
pypck.inputs.ModStatusLedsAndLogicOps):
|
||||
if not isinstance(input_obj, pypck.inputs.ModStatusLedsAndLogicOps):
|
||||
return
|
||||
|
||||
if self.source in pypck.lcn_defs.LedPort:
|
||||
self._value = input_obj.get_led_state(
|
||||
self.source.value).name.lower()
|
||||
self._value = input_obj.get_led_state(self.source.value).name.lower()
|
||||
elif self.source in pypck.lcn_defs.LogicOpPort:
|
||||
self._value = input_obj.get_logic_op_state(
|
||||
self.source.value).name.lower()
|
||||
self._value = input_obj.get_logic_op_state(self.source.value).name.lower()
|
||||
|
||||
self.async_schedule_update_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue