Connect from frontend

This commit is contained in:
2019-06-26 23:51:59 +02:00
parent 1e0bc60220
commit f50a5a84f0
4 changed files with 43 additions and 4 deletions

View File

@@ -1,10 +1,13 @@
import logging
import voluptuous as vol
from homeassistant.components.websocket_api import websocket_command, result_message, async_register_command
from .mod_view import setup_view
REQUIREMENTS = ["aiofiles"]
FRONTEND_SCRIPT_URL '/browser_mod.js'
FRONTEND_SCRIPT_URL = '/browser_mod.js'
_LOGGER = logging.getLogger(__name__)
@@ -14,5 +17,17 @@ async def async_setup(hass, config):
setup_view(hass, FRONTEND_SCRIPT_URL)
_LOGGER.error(f"Registered frontend script")
async_register_command(hass, handle_connect)
return True
@websocket_command({
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']))