mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
add device info API (#20950)
This commit is contained in:
parent
861d58f58f
commit
868820c424
@ -14,14 +14,13 @@ import homeassistant.helpers.config_validation as cv
|
||||
from .core.const import (
|
||||
DOMAIN, ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, ATTR_ATTRIBUTE, ATTR_VALUE,
|
||||
ATTR_MANUFACTURER, ATTR_COMMAND, ATTR_COMMAND_TYPE, ATTR_ARGS, IN, OUT,
|
||||
CLIENT_COMMANDS, SERVER_COMMANDS, SERVER)
|
||||
CLIENT_COMMANDS, SERVER_COMMANDS, SERVER, NAME)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TYPE = 'type'
|
||||
CLIENT = 'client'
|
||||
ID = 'id'
|
||||
NAME = 'name'
|
||||
RESPONSE = 'response'
|
||||
DEVICE_INFO = 'device_info'
|
||||
|
||||
@ -74,6 +73,11 @@ SCHEMA_WS_RECONFIGURE_NODE = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
vol.Required(ATTR_IEEE): str
|
||||
})
|
||||
|
||||
WS_DEVICES = 'zha/devices'
|
||||
SCHEMA_WS_LIST_DEVICES = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
vol.Required(TYPE): WS_DEVICES,
|
||||
})
|
||||
|
||||
WS_ENTITIES_BY_IEEE = 'zha/entities'
|
||||
SCHEMA_WS_LIST = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
vol.Required(TYPE): WS_ENTITIES_BY_IEEE,
|
||||
@ -215,6 +219,29 @@ def async_load_api(hass, application_controller, zha_gateway):
|
||||
SERVICE_ISSUE_ZIGBEE_CLUSTER_COMMAND
|
||||
])
|
||||
|
||||
@websocket_api.async_response
|
||||
async def websocket_get_devices(hass, connection, msg):
|
||||
"""Get ZHA devices."""
|
||||
devices = [
|
||||
{
|
||||
**device.device_info,
|
||||
'entities': [{
|
||||
'entity_id': entity_ref.reference_id,
|
||||
NAME: entity_ref.device_info[NAME]
|
||||
} for entity_ref in zha_gateway.device_registry[device.ieee]]
|
||||
} for device in zha_gateway.devices.values()
|
||||
]
|
||||
|
||||
connection.send_message(websocket_api.result_message(
|
||||
msg[ID],
|
||||
devices
|
||||
))
|
||||
|
||||
hass.components.websocket_api.async_register_command(
|
||||
WS_DEVICES, websocket_get_devices,
|
||||
SCHEMA_WS_LIST_DEVICES
|
||||
)
|
||||
|
||||
@websocket_api.async_response
|
||||
async def websocket_reconfigure_node(hass, connection, msg):
|
||||
"""Reconfigure a ZHA nodes entities by its ieee address."""
|
||||
|
@ -5,10 +5,12 @@ from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.components.switch import DOMAIN
|
||||
from homeassistant.components.zha.api import (
|
||||
async_load_api, WS_ENTITIES_BY_IEEE, WS_ENTITY_CLUSTERS, ATTR_IEEE, TYPE,
|
||||
ID, NAME, WS_ENTITY_CLUSTER_ATTRIBUTES, WS_ENTITY_CLUSTER_COMMANDS
|
||||
ID, WS_ENTITY_CLUSTER_ATTRIBUTES, WS_ENTITY_CLUSTER_COMMANDS,
|
||||
WS_DEVICES
|
||||
)
|
||||
from homeassistant.components.zha.core.const import (
|
||||
ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, IN
|
||||
ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, IN, IEEE, MODEL, NAME, QUIRK_APPLIED,
|
||||
ATTR_MANUFACTURER
|
||||
)
|
||||
from .common import async_init_zigpy_device
|
||||
|
||||
@ -109,3 +111,29 @@ async def test_entity_cluster_commands(
|
||||
assert command[ID] is not None
|
||||
assert command[NAME] is not None
|
||||
assert command[TYPE] is not None
|
||||
|
||||
|
||||
async def test_list_devices(
|
||||
hass, config_entry, zha_gateway, zha_client):
|
||||
"""Test getting entity cluster commands."""
|
||||
await zha_client.send_json({
|
||||
ID: 5,
|
||||
TYPE: WS_DEVICES
|
||||
})
|
||||
|
||||
msg = await zha_client.receive_json()
|
||||
|
||||
devices = msg['result']
|
||||
assert len(devices) == 1
|
||||
|
||||
for device in devices:
|
||||
assert device[IEEE] is not None
|
||||
assert device[ATTR_MANUFACTURER] is not None
|
||||
assert device[MODEL] is not None
|
||||
assert device[NAME] is not None
|
||||
assert device[QUIRK_APPLIED] is not None
|
||||
assert device['entities'] is not None
|
||||
|
||||
for entity_reference in device['entities']:
|
||||
assert entity_reference[NAME] is not None
|
||||
assert entity_reference['entity_id'] is not None
|
||||
|
Loading…
x
Reference in New Issue
Block a user