Code cleanup in LCN (#48074)
This commit is contained in:
parent
bdb8cdf717
commit
c868353459
6 changed files with 15 additions and 57 deletions
|
@ -15,13 +15,11 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import CONF_DIM_MODE, CONF_SK_NUM_TRIES, CONNECTION, DOMAIN
|
||||
from .const import CONF_DIM_MODE, CONF_SK_NUM_TRIES, CONNECTION, DOMAIN, PLATFORMS
|
||||
from .helpers import generate_unique_id, import_lcn_config
|
||||
from .schemas import CONFIG_SCHEMA # noqa: F401
|
||||
from .services import SERVICES
|
||||
|
||||
PLATFORMS = ["binary_sensor", "climate", "cover", "light", "scene", "sensor", "switch"]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -89,7 +89,4 @@ class LcnFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self.hass.config_entries.async_update_entry(entry, data=data)
|
||||
return self.async_abort(reason="existing_configuration_updated")
|
||||
|
||||
return self.async_create_entry(
|
||||
title=f"{host_name}",
|
||||
data=data,
|
||||
)
|
||||
return self.async_create_entry(title=f"{host_name}", data=data)
|
||||
|
|
|
@ -10,6 +10,8 @@ from homeassistant.const import (
|
|||
VOLT,
|
||||
)
|
||||
|
||||
PLATFORMS = ["binary_sensor", "climate", "cover", "light", "scene", "sensor", "switch"]
|
||||
|
||||
DOMAIN = "lcn"
|
||||
DATA_LCN = "lcn"
|
||||
DEFAULT_NAME = "pchk"
|
||||
|
|
|
@ -224,44 +224,12 @@ def is_address(value):
|
|||
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.")
|
||||
raise ValueError(f"{value} is not a valid address string")
|
||||
|
||||
|
||||
def is_relays_states_string(states_string):
|
||||
def is_states_string(states_string):
|
||||
"""Validate the given states string and return states list."""
|
||||
if len(states_string) == 8:
|
||||
states = []
|
||||
for state_string in states_string:
|
||||
if state_string == "1":
|
||||
state = "ON"
|
||||
elif state_string == "0":
|
||||
state = "OFF"
|
||||
elif state_string == "T":
|
||||
state = "TOGGLE"
|
||||
elif state_string == "-":
|
||||
state = "NOCHANGE"
|
||||
else:
|
||||
raise vol.error.Invalid("Not a valid relay state string.")
|
||||
states.append(state)
|
||||
return states
|
||||
raise vol.error.Invalid("Wrong length of relay state string.")
|
||||
|
||||
|
||||
def is_key_lock_states_string(states_string):
|
||||
"""Validate the given states string and returns states list."""
|
||||
if len(states_string) == 8:
|
||||
states = []
|
||||
for state_string in states_string:
|
||||
if state_string == "1":
|
||||
state = "ON"
|
||||
elif state_string == "0":
|
||||
state = "OFF"
|
||||
elif state_string == "T":
|
||||
state = "TOGGLE"
|
||||
elif state_string == "-":
|
||||
state = "NOCHANGE"
|
||||
else:
|
||||
raise vol.error.Invalid("Not a valid key lock state string.")
|
||||
states.append(state)
|
||||
return states
|
||||
raise vol.error.Invalid("Wrong length of key lock state string.")
|
||||
if len(states_string) != 8:
|
||||
raise ValueError("Invalid length of states string")
|
||||
states = {"1": "ON", "0": "OFF", "T": "TOGGLE", "-": "NOCHANGE"}
|
||||
return [states[state_string] for state_string in states_string]
|
||||
|
|
|
@ -40,12 +40,7 @@ from .const import (
|
|||
VAR_UNITS,
|
||||
VARIABLES,
|
||||
)
|
||||
from .helpers import (
|
||||
get_device_connection,
|
||||
is_address,
|
||||
is_key_lock_states_string,
|
||||
is_relays_states_string,
|
||||
)
|
||||
from .helpers import get_device_connection, is_address, is_states_string
|
||||
|
||||
|
||||
class LcnServiceCall:
|
||||
|
@ -150,9 +145,7 @@ class OutputToggle(LcnServiceCall):
|
|||
class Relays(LcnServiceCall):
|
||||
"""Set the relays status."""
|
||||
|
||||
schema = LcnServiceCall.schema.extend(
|
||||
{vol.Required(CONF_STATE): is_relays_states_string}
|
||||
)
|
||||
schema = LcnServiceCall.schema.extend({vol.Required(CONF_STATE): is_states_string})
|
||||
|
||||
async def async_call_service(self, service):
|
||||
"""Execute service call."""
|
||||
|
@ -330,7 +323,7 @@ class LockKeys(LcnServiceCall):
|
|||
vol.Optional(CONF_TABLE, default="a"): vol.All(
|
||||
vol.Upper, cv.matches_regex(r"^[A-D]$")
|
||||
),
|
||||
vol.Required(CONF_STATE): is_key_lock_states_string,
|
||||
vol.Required(CONF_STATE): is_states_string,
|
||||
vol.Optional(CONF_TIME, default=0): cv.positive_int,
|
||||
vol.Optional(CONF_TIME_UNIT, default=TIME_SECONDS): vol.All(
|
||||
vol.Upper, vol.In(TIME_UNITS)
|
||||
|
@ -361,7 +354,7 @@ class LockKeys(LcnServiceCall):
|
|||
else:
|
||||
await device_connection.lock_keys(table_id, states)
|
||||
|
||||
handler = device_connection.status_request_handler
|
||||
handler = device_connection.status_requests_handler
|
||||
await handler.request_status_locked_keys_timeout()
|
||||
|
||||
|
||||
|
|
|
@ -521,7 +521,7 @@ lock_keys:
|
|||
table:
|
||||
name: Table
|
||||
description: "Table with keys to lock (must be A for interval)."
|
||||
example: "a5"
|
||||
example: "a"
|
||||
default: a
|
||||
selector:
|
||||
text:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue