Add service for each command
This commit is contained in:
parent
f13ac064ca
commit
939a87def9
@ -15,3 +15,15 @@ WS_ROOT = DOMAIN
|
||||
WS_CONNECT = "{}/connect".format(WS_ROOT)
|
||||
WS_UPDATE = "{}/update".format(WS_ROOT)
|
||||
WS_CAMERA = "{}/camera".format(WS_ROOT)
|
||||
|
||||
USER_COMMANDS = [
|
||||
"debug",
|
||||
"popup",
|
||||
"close-popup",
|
||||
"navigate",
|
||||
"more-info",
|
||||
"set-theme",
|
||||
"lovelace-reload",
|
||||
"blackout",
|
||||
"no-blackout",
|
||||
]
|
||||
|
@ -1,4 +1,7 @@
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES
|
||||
import logging
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, USER_COMMANDS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def setup_service(hass):
|
||||
|
||||
@ -8,6 +11,8 @@ def setup_service(hass):
|
||||
return
|
||||
|
||||
targets = call.data.get("deviceID", None)
|
||||
if isinstance(targets, str):
|
||||
targets = [targets]
|
||||
devices = hass.data[DOMAIN][DATA_DEVICES]
|
||||
aliases = hass.data[DOMAIN][DATA_ALIASES]
|
||||
if not targets:
|
||||
@ -21,4 +26,12 @@ def setup_service(hass):
|
||||
if t in devices:
|
||||
devices[t].send(command, **data)
|
||||
|
||||
def command_wrapper(call):
|
||||
command = call.service.replace('_','-')
|
||||
call.data = dict(call.data)
|
||||
call.data['command'] = command
|
||||
handle_command(call)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'command', handle_command)
|
||||
for cmd in USER_COMMANDS:
|
||||
hass.services.async_register(DOMAIN, cmd.replace('-','_'), command_wrapper)
|
||||
|
Loading…
x
Reference in New Issue
Block a user