Add suggested area for zwave_js devices (#47250)

pull/45902/head
Raman Gupta 2021-03-01 18:24:55 -05:00 committed by GitHub
parent c6cfcc2abb
commit 3e34bb3e89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 17 deletions

View File

@ -67,14 +67,17 @@ def register_node_in_dev_reg(
node: ZwaveNode,
) -> None:
"""Register node in dev reg."""
device = dev_reg.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={get_device_id(client, node)},
sw_version=node.firmware_version,
name=node.name or node.device_config.description or f"Node {node.node_id}",
model=node.device_config.label,
manufacturer=node.device_config.manufacturer,
)
params = {
"config_entry_id": entry.entry_id,
"identifiers": {get_device_id(client, node)},
"sw_version": node.firmware_version,
"name": node.name or node.device_config.description or f"Node {node.node_id}",
"model": node.device_config.label,
"manufacturer": node.device_config.manufacturer,
}
if node.location:
params["suggested_area"] = node.location
device = dev_reg.async_get_or_create(**params)
async_dispatcher_send(hass, EVENT_DEVICE_ADDED_TO_REGISTRY, device)

View File

@ -16,3 +16,6 @@ PROPERTY_DOOR_STATUS_BINARY_SENSOR = (
CLIMATE_RADIO_THERMOSTAT_ENTITY = "climate.z_wave_thermostat"
CLIMATE_DANFOSS_LC13_ENTITY = "climate.living_connect_z_thermostat"
CLIMATE_FLOOR_THERMOSTAT_ENTITY = "climate.floor_thermostat"
BULB_6_MULTI_COLOR_LIGHT_ENTITY = "light.bulb_6_multi_color"
EATON_RF9640_ENTITY = "light.allloaddimmer"
AEON_SMART_SWITCH_LIGHT_ENTITY = "light.smart_switch_6"

View File

@ -10,9 +10,7 @@ from zwave_js_server.model.driver import Driver
from zwave_js_server.model.node import Node
from zwave_js_server.version import VersionInfo
from homeassistant.helpers.device_registry import (
async_get_registry as async_get_device_registry,
)
from homeassistant.helpers.device_registry import async_get as async_get_device_registry
from tests.common import MockConfigEntry, load_fixture
@ -20,7 +18,7 @@ from tests.common import MockConfigEntry, load_fixture
@pytest.fixture(name="device_registry")
async def device_registry_fixture(hass):
"""Return the device registry."""
return await async_get_device_registry(hass)
return async_get_device_registry(hass)
@pytest.fixture(name="controller_state", scope="session")

View File

@ -18,7 +18,11 @@ from homeassistant.config_entries import (
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry, entity_registry
from .common import AIR_TEMPERATURE_SENSOR, NOTIFICATION_MOTION_BINARY_SENSOR
from .common import (
AIR_TEMPERATURE_SENSOR,
EATON_RF9640_ENTITY,
NOTIFICATION_MOTION_BINARY_SENSOR,
)
from tests.common import MockConfigEntry
@ -467,3 +471,17 @@ async def test_removed_device(hass, client, multiple_devices, integration):
)
assert len(entity_entries) == 15
assert dev_reg.async_get_device({get_device_id(client, old_node)}) is None
async def test_suggested_area(hass, client, eaton_rf9640_dimmer):
"""Test that suggested area works."""
dev_reg = device_registry.async_get(hass)
ent_reg = entity_registry.async_get(hass)
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"})
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
entity = ent_reg.async_get(EATON_RF9640_ENTITY)
assert dev_reg.async_get(entity.device_id).area_id is not None

View File

@ -12,9 +12,11 @@ from homeassistant.components.light import (
)
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
BULB_6_MULTI_COLOR_LIGHT_ENTITY = "light.bulb_6_multi_color"
EATON_RF9640_ENTITY = "light.allloaddimmer"
AEON_SMART_SWITCH_LIGHT_ENTITY = "light.smart_switch_6"
from .common import (
AEON_SMART_SWITCH_LIGHT_ENTITY,
BULB_6_MULTI_COLOR_LIGHT_ENTITY,
EATON_RF9640_ENTITY,
)
async def test_light(hass, client, bulb_6_multi_color, integration):

View File

@ -27,7 +27,7 @@
"nodeType": 0,
"roleType": 5,
"name": "AllLoadDimmer",
"location": "",
"location": "LivingRoom",
"deviceConfig": {
"manufacturerId": 26,
"manufacturer": "Eaton",