Add usb_path to Z-Wave network_status websocket response (#25617)
* Add usb stick path to zwave network_status websocket response * Move to separate websocket command * Return additional config options * add tests
This commit is contained in:
parent
70dfe42adb
commit
0a87a4bfda
2 changed files with 63 additions and 1 deletions
|
@ -7,7 +7,14 @@ import voluptuous as vol
|
|||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import DATA_NETWORK
|
||||
from .const import (
|
||||
CONF_AUTOHEAL,
|
||||
CONF_DEBUG,
|
||||
CONF_POLLING_INTERVAL,
|
||||
CONF_USB_STICK_PATH,
|
||||
DATA_NETWORK,
|
||||
DATA_ZWAVE_CONFIG,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -23,7 +30,24 @@ def websocket_network_status(hass, connection, msg):
|
|||
connection.send_result(msg[ID], {"state": network.state})
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command({vol.Required(TYPE): "zwave/get_config"})
|
||||
def websocket_get_config(hass, connection, msg):
|
||||
"""Get Z-Wave configuration."""
|
||||
config = hass.data[DATA_ZWAVE_CONFIG]
|
||||
connection.send_result(
|
||||
msg[ID],
|
||||
{
|
||||
CONF_AUTOHEAL: config[CONF_AUTOHEAL],
|
||||
CONF_DEBUG: config[CONF_DEBUG],
|
||||
CONF_POLLING_INTERVAL: config[CONF_POLLING_INTERVAL],
|
||||
CONF_USB_STICK_PATH: config[CONF_USB_STICK_PATH],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_load_websocket_api(hass):
|
||||
"""Set up the web socket API."""
|
||||
websocket_api.async_register_command(hass, websocket_network_status)
|
||||
websocket_api.async_register_command(hass, websocket_get_config)
|
||||
|
|
38
tests/components/zwave/test_websocket_api.py
Normal file
38
tests/components/zwave/test_websocket_api.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""Test Z-Wave Websocket API."""
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
|
||||
from homeassistant.components.zwave.const import (
|
||||
CONF_USB_STICK_PATH,
|
||||
CONF_AUTOHEAL,
|
||||
CONF_POLLING_INTERVAL,
|
||||
)
|
||||
from homeassistant.components.zwave.websocket_api import ID, TYPE
|
||||
|
||||
|
||||
async def test_zwave_ws_api(hass, mock_openzwave, hass_ws_client):
|
||||
"""Test Z-Wave websocket API."""
|
||||
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"zwave",
|
||||
{
|
||||
"zwave": {
|
||||
CONF_AUTOHEAL: False,
|
||||
CONF_USB_STICK_PATH: "/dev/zwave",
|
||||
CONF_POLLING_INTERVAL: 6000,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json({ID: 5, TYPE: "zwave/get_config"})
|
||||
|
||||
msg = await client.receive_json()
|
||||
result = msg["result"]
|
||||
|
||||
assert result[CONF_USB_STICK_PATH] == "/dev/zwave"
|
||||
assert not result[CONF_AUTOHEAL]
|
||||
assert result[CONF_POLLING_INTERVAL] == 6000
|
Loading…
Add table
Add a link
Reference in a new issue