Service to send command to browsers
This commit is contained in:
parent
4149759dd1
commit
f58467445c
@ -2,6 +2,7 @@ import logging
|
||||
|
||||
from .mod_view import setup_view
|
||||
from .connection import setup_connection
|
||||
from .service import setup_service
|
||||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES
|
||||
|
||||
|
||||
@ -32,4 +33,6 @@ async def async_setup(hass, config):
|
||||
|
||||
setup_connection(hass)
|
||||
|
||||
setup_service(hass)
|
||||
|
||||
return True
|
||||
|
@ -53,6 +53,7 @@ class BrowserModEntity(Entity):
|
||||
self.entity_id = async_generate_entity_id("media_player.{}", alias or deviceID, hass=hass)
|
||||
|
||||
def ws_send(self, command, **kwargs):
|
||||
if self._ws_connection:
|
||||
self._ws_connection.send_message(event_message(self._ws_cid, {
|
||||
"command": command,
|
||||
**kwargs,
|
||||
|
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)
|
9
custom_components/browser_mod/services.yaml
Normal file
9
custom_components/browser_mod/services.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
command:
|
||||
description: Send a command to a browser
|
||||
fields:
|
||||
command:
|
||||
description: Command to send
|
||||
example: 'navigate'
|
||||
deviceID:
|
||||
description: List of receiving browsers
|
||||
example: '["99980b13-dabc9563", "office_computer"]'
|
Loading…
x
Reference in New Issue
Block a user