Skip to content

Commit

Permalink
Add service calls for LCN component (#24105)
Browse files Browse the repository at this point in the history
  • Loading branch information
alengwenus authored and balloob committed May 29, 2019
1 parent 9303a56 commit 50db622
Show file tree
Hide file tree
Showing 5 changed files with 611 additions and 1 deletion.
21 changes: 21 additions & 0 deletions homeassistant/components/lcn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
LOGICOP_PORTS, MOTOR_PORTS, OUTPUT_PORTS, RELAY_PORTS, S0_INPUTS,
SETPOINTS, THRESHOLDS, VAR_UNITS, VARIABLES)
from .helpers import has_unique_connection_names, is_address
from .services import (
DynText, Led, LockKeys, LockRegulator, OutputAbs, OutputRel, OutputToggle,
Pck, Relays, SendKeys, VarAbs, VarRel, VarReset)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -155,6 +158,24 @@ async def async_setup(hass, config):
hass.async_create_task(
async_load_platform(hass, component, DOMAIN,
config[DOMAIN][conf_key], config))

# register service calls
for service_name, service in (('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)):
hass.services.async_register(DOMAIN, service_name,
service(hass), service.schema)

return True


Expand Down
24 changes: 23 additions & 1 deletion homeassistant/components/lcn/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@
CONF_DIMMABLE = 'dimmable'
CONF_TRANSITION = 'transition'
CONF_MOTOR = 'motor'
CONF_LOCKABLE = 'lockable'
CONF_VARIABLE = 'variable'
CONF_VALUE = 'value'
CONF_RELVARREF = 'value_reference'
CONF_SOURCE = 'source'
CONF_SETPOINT = 'setpoint'
CONF_LOCKABLE = 'lockable'
CONF_LED = 'led'
CONF_KEYS = 'keys'
CONF_TIME = 'time'
CONF_TIME_UNIT = 'time_unit'
CONF_TABLE = 'table'
CONF_ROW = 'row'
CONF_TEXT = 'text'
CONF_PCK = 'pck'
CONF_CLIMATES = 'climates'
CONF_MAX_TEMP = 'max_temp'
CONF_MIN_TEMP = 'min_temp'
Expand All @@ -36,6 +47,8 @@
LED_PORTS = ['LED1', 'LED2', 'LED3', 'LED4', 'LED5', 'LED6',
'LED7', 'LED8', 'LED9', 'LED10', 'LED11', 'LED12']

LED_STATUS = ['OFF', 'ON', 'BLINK', 'FLICKER']

LOGICOP_PORTS = ['LOGICOP1', 'LOGICOP2', 'LOGICOP3', 'LOGICOP4']

BINSENSOR_PORTS = ['BINSENSOR1', 'BINSENSOR2', 'BINSENSOR3', 'BINSENSOR4',
Expand Down Expand Up @@ -70,3 +83,12 @@
'VOLT', 'V',
'AMPERE', 'AMP', 'A',
'DEGREE', '°']

RELVARREF = ['CURRENT', 'PROG']

SENDKEYCOMMANDS = ['HIT', 'MAKE', 'BREAK', 'DONTSEND']

TIME_UNITS = ['SECONDS', 'SECOND', 'SEC', 'S',
'MINUTES', 'MINUTE', 'MIN', 'M',
'HOURS', 'HOUR', 'H',
'DAYS', 'DAY', 'D']
40 changes: 40 additions & 0 deletions homeassistant/components/lcn/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,43 @@ def is_address(value):
conn_id = matcher.group('conn_id')
return addr, conn_id
raise vol.error.Invalid('Not a valid address string.')


def is_relays_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.')
Loading

0 comments on commit 50db622

Please sign in to comment.