Migrate LCN configuration to ConfigEntry (Part 1) (#44090)
This commit is contained in:
parent
fb34d1a56e
commit
50b7b1cc7a
17 changed files with 885 additions and 350 deletions
|
@ -6,6 +6,7 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
CONF_ADDRESS,
|
||||
CONF_BRIGHTNESS,
|
||||
CONF_HOST,
|
||||
CONF_STATE,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
TIME_SECONDS,
|
||||
|
@ -13,7 +14,6 @@ from homeassistant.const import (
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from .const import (
|
||||
CONF_CONNECTIONS,
|
||||
CONF_KEYS,
|
||||
CONF_LED,
|
||||
CONF_OUTPUT,
|
||||
|
@ -28,7 +28,7 @@ from .const import (
|
|||
CONF_TRANSITION,
|
||||
CONF_VALUE,
|
||||
CONF_VARIABLE,
|
||||
DATA_LCN,
|
||||
DOMAIN,
|
||||
LED_PORTS,
|
||||
LED_STATUS,
|
||||
OUTPUT_PORTS,
|
||||
|
@ -41,7 +41,7 @@ from .const import (
|
|||
VARIABLES,
|
||||
)
|
||||
from .helpers import (
|
||||
get_connection,
|
||||
get_device_connection,
|
||||
is_address,
|
||||
is_key_lock_states_string,
|
||||
is_relays_states_string,
|
||||
|
@ -56,18 +56,20 @@ class LcnServiceCall:
|
|||
def __init__(self, hass):
|
||||
"""Initialize service call."""
|
||||
self.hass = hass
|
||||
self.connections = hass.data[DATA_LCN][CONF_CONNECTIONS]
|
||||
|
||||
def get_device_connection(self, service):
|
||||
"""Get device connection object."""
|
||||
addr, connection_id = service.data[CONF_ADDRESS]
|
||||
addr = pypck.lcn_addr.LcnAddr(*addr)
|
||||
if connection_id is None:
|
||||
connection = self.connections[0]
|
||||
else:
|
||||
connection = get_connection(self.connections, connection_id)
|
||||
"""Get address connection object."""
|
||||
address, host_name = service.data[CONF_ADDRESS]
|
||||
|
||||
return connection.get_address_conn(addr)
|
||||
for config_entry in self.hass.config_entries.async_entries(DOMAIN):
|
||||
if config_entry.data[CONF_HOST] == host_name:
|
||||
device_connection = get_device_connection(
|
||||
self.hass, address, config_entry
|
||||
)
|
||||
if device_connection is None:
|
||||
raise ValueError("Wrong address.")
|
||||
return device_connection
|
||||
raise ValueError("Invalid host name.")
|
||||
|
||||
async def async_call_service(self, service):
|
||||
"""Execute service call."""
|
||||
|
@ -392,3 +394,20 @@ class Pck(LcnServiceCall):
|
|||
pck = service.data[CONF_PCK]
|
||||
device_connection = self.get_device_connection(service)
|
||||
await device_connection.pck(pck)
|
||||
|
||||
|
||||
SERVICES = (
|
||||
("output_abs", OutputAbs),
|
||||
("output_rel", OutputRel),
|
||||
("output_toggle", OutputToggle),
|
||||
("relays", Relays),
|
||||
("var_abs", VarAbs),
|
||||
("var_reset", VarReset),
|
||||
("var_rel", VarRel),
|
||||
("lock_regulator", LockRegulator),
|
||||
("led", Led),
|
||||
("send_keys", SendKeys),
|
||||
("lock_keys", LockKeys),
|
||||
("dyn_text", DynText),
|
||||
("pck", Pck),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue