Add zwave_js WS API cmds to get node state and version info (#51396)
* Add zwave_js view to retrieve a node's state * remove typehints * Make dump views require admin * Add version info to node level dump * Add back typehints * switch from list to dict * switch from dump node view to two WS API commands * switch to snake
This commit is contained in:
parent
f00f2b4ae4
commit
8705168fe6
2 changed files with 189 additions and 2 deletions
|
@ -138,6 +138,7 @@ def async_register_api(hass: HomeAssistant) -> None:
|
|||
"""Register all of our api endpoints."""
|
||||
websocket_api.async_register_command(hass, websocket_network_status)
|
||||
websocket_api.async_register_command(hass, websocket_node_status)
|
||||
websocket_api.async_register_command(hass, websocket_node_state)
|
||||
websocket_api.async_register_command(hass, websocket_node_metadata)
|
||||
websocket_api.async_register_command(hass, websocket_ping_node)
|
||||
websocket_api.async_register_command(hass, websocket_add_node)
|
||||
|
@ -164,6 +165,7 @@ def async_register_api(hass: HomeAssistant) -> None:
|
|||
hass, websocket_update_data_collection_preference
|
||||
)
|
||||
websocket_api.async_register_command(hass, websocket_data_collection_status)
|
||||
websocket_api.async_register_command(hass, websocket_version_info)
|
||||
websocket_api.async_register_command(hass, websocket_abort_firmware_update)
|
||||
websocket_api.async_register_command(
|
||||
hass, websocket_subscribe_firmware_update_status
|
||||
|
@ -253,6 +255,28 @@ async def websocket_node_status(
|
|||
)
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required(TYPE): "zwave_js/node_state",
|
||||
vol.Required(ENTRY_ID): str,
|
||||
vol.Required(NODE_ID): int,
|
||||
}
|
||||
)
|
||||
@websocket_api.async_response
|
||||
@async_get_node
|
||||
async def websocket_node_state(
|
||||
hass: HomeAssistant,
|
||||
connection: ActiveConnection,
|
||||
msg: dict,
|
||||
node: Node,
|
||||
) -> None:
|
||||
"""Get the state data of a Z-Wave JS node."""
|
||||
connection.send_result(
|
||||
msg[ID],
|
||||
node.data,
|
||||
)
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required(TYPE): "zwave_js/node_metadata",
|
||||
|
@ -1170,6 +1194,8 @@ class DumpView(HomeAssistantView):
|
|||
|
||||
async def get(self, request: web.Request, config_entry_id: str) -> web.Response:
|
||||
"""Dump the state of Z-Wave."""
|
||||
if not request["hass_user"].is_admin:
|
||||
raise Unauthorized()
|
||||
hass = request.app["hass"]
|
||||
|
||||
if config_entry_id not in hass.data[DOMAIN]:
|
||||
|
@ -1188,6 +1214,35 @@ class DumpView(HomeAssistantView):
|
|||
)
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required(TYPE): "zwave_js/version_info",
|
||||
vol.Required(ENTRY_ID): str,
|
||||
},
|
||||
)
|
||||
@websocket_api.async_response
|
||||
@async_get_entry
|
||||
async def websocket_version_info(
|
||||
hass: HomeAssistant,
|
||||
connection: ActiveConnection,
|
||||
msg: dict,
|
||||
entry: ConfigEntry,
|
||||
client: Client,
|
||||
) -> None:
|
||||
"""Get version info from the Z-Wave JS server."""
|
||||
version_info = {
|
||||
"driver_version": client.version.driver_version,
|
||||
"server_version": client.version.server_version,
|
||||
"min_schema_version": client.version.min_schema_version,
|
||||
"max_schema_version": client.version.max_schema_version,
|
||||
}
|
||||
connection.send_result(
|
||||
msg[ID],
|
||||
version_info,
|
||||
)
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
|
@ -1287,7 +1342,7 @@ class FirmwareUploadView(HomeAssistantView):
|
|||
raise web_exceptions.HTTPBadRequest
|
||||
|
||||
entry = hass.config_entries.async_get_entry(config_entry_id)
|
||||
client = hass.data[DOMAIN][config_entry_id][DATA_CLIENT]
|
||||
client: Client = hass.data[DOMAIN][config_entry_id][DATA_CLIENT]
|
||||
node = client.driver.controller.nodes.get(int(node_id))
|
||||
if not node:
|
||||
raise web_exceptions.HTTPNotFound
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue