Some backend configuration setup

This commit is contained in:
2019-06-27 00:13:18 +02:00
parent 64c8c2d49b
commit 5d3d55977b
3 changed files with 44 additions and 8 deletions

View File

@@ -5,9 +5,9 @@ from homeassistant.components.websocket_api import websocket_command, result_mes
from .mod_view import setup_view
REQUIREMENTS = ["aiofiles"]
DOMAIN = "browser_mod"
FRONTEND_SCRIPT_URL = '/browser_mod.js'
FRONTEND_SCRIPT_URL = "/browser_mod.js"
_LOGGER = logging.getLogger(__name__)
@@ -18,18 +18,43 @@ async def async_setup(hass, config):
_LOGGER.error(f"Registered frontend script")
async_register_command(hass, handle_connect)
_LOGGER.error(f"Registered connect ws command")
_LOGGER.error(f"Config")
_LOGGER.error(config)
aliases = {}
for d in config[DOMAIN].get("devices", {}):
name = config[DOMAIN]["devices"][d].get("name", None)
if name:
aliases[name] = d
_LOGGER.error(aliases)
hass.data[DOMAIN] = {
"devices": {},
"aliases": aliases,
}
return True
@websocket_command({
vol.Required('type'): 'browser_mod/connect',
vol.Required('deviceID'): str,
vol.Required("type"): "browser_mod/connect",
vol.Required("deviceID"): str,
})
def handle_connect(hass, connection, msg):
_LOGGER.error(f"Got connection {msg}")
connection.send_message(result_message(msg['id']))
connection.send_message(result_message(msg["id"]))
connection.send_message(event_message(msg['id'], {"data": "something"}))
connection.send_message(event_message(msg["id"], {"command": "update"}))
@websocket_command({
vol.Required("type"): "browser_mod/update",
vol.Required("deviceID"): str,
vol.Optional("browser"): dict,
vol.Optional("player"): dict,
})
def handle_update(hass, connection, msg):
pass