Service to send command to browsers

This commit is contained in:
2019-06-27 13:30:54 +02:00
parent 4149759dd1
commit f58467445c
4 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES
def setup_service(hass):
def handle_command(call):
command = call.data.get("command", None)
if not command:
return
targets = call.data.get("deviceID", None)
devices = hass.data[DOMAIN][DATA_DEVICES]
aliases = hass.data[DOMAIN][DATA_ALIASES]
if not targets:
targets = devices.keys()
targets = [aliases.get(t, t) for t in targets]
data = dict(call.data)
del data["command"]
for t in targets:
if t in devices:
devices[t].ws_send(command, **data)
hass.services.async_register(DOMAIN, 'command', handle_command)