Skip to content

Commit

Permalink
Add websocket API command for Z-Wave network status (home-assistant#2…
Browse files Browse the repository at this point in the history
…5066)

* Add websocket API command for Z-Wave network status

* lint

* Add callback decorator

* Remove state_str, fix lint
  • Loading branch information
cgarwood authored and balloob committed Jul 11, 2019
1 parent 42d2f30 commit 312fcee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from . import const
from . import config_flow # noqa pylint: disable=unused-import
from . import websocket_api as wsapi
from .const import (
CONF_AUTOHEAL, CONF_DEBUG, CONF_POLLING_INTERVAL,
CONF_USB_STICK_PATH, CONF_CONFIG_PATH, CONF_NETWORK_KEY,
Expand Down Expand Up @@ -301,6 +302,8 @@ async def async_setup_entry(hass, config_entry):

registry = await async_get_registry(hass)

wsapi.async_load_websocket_api(hass)

if use_debug: # pragma: no cover
def log_all(signal, value=None):
"""Log all the signals."""
Expand Down
33 changes: 33 additions & 0 deletions homeassistant/components/zwave/websocket_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Web socket API for Z-Wave."""

import logging

import voluptuous as vol

from homeassistant.components import websocket_api
from homeassistant.core import callback

from .const import DATA_NETWORK

_LOGGER = logging.getLogger(__name__)

TYPE = 'type'
ID = 'id'


@websocket_api.require_admin
@websocket_api.websocket_command({
vol.Required(TYPE): 'zwave/network_status'
})
def websocket_network_status(hass, connection, msg):
"""Get Z-Wave network status."""
network = hass.data[DATA_NETWORK]
connection.send_result(msg[ID], {
'state': network.state,
})


@callback
def async_load_websocket_api(hass):
"""Set up the web socket API."""
websocket_api.async_register_command(hass, websocket_network_status)

0 comments on commit 312fcee

Please sign in to comment.