Service to send command to browsers
This commit is contained in:
24
custom_components/browser_mod/service.py
Normal file
24
custom_components/browser_mod/service.py
Normal 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)
|
||||
Reference in New Issue
Block a user