Fix zwave_js discovery logic for node device class (#117232)

* Fix zwave_js discovery logic for node device class

* simplify check
This commit is contained in:
Raman Gupta 2024-05-11 11:41:03 -04:00 committed by GitHub
parent 3bea124d84
commit 9655db3d55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10649 additions and 17 deletions

View File

@ -41,7 +41,6 @@ from zwave_js_server.const.command_class.thermostat import (
THERMOSTAT_SETPOINT_PROPERTY,
)
from zwave_js_server.exceptions import UnknownValueData
from zwave_js_server.model.device_class import DeviceClassItem
from zwave_js_server.model.node import Node as ZwaveNode
from zwave_js_server.model.value import (
ConfigurationValue,
@ -1235,14 +1234,22 @@ def async_discover_single_value(
continue
# check device_class_generic
if value.node.device_class and not check_device_class(
value.node.device_class.generic, schema.device_class_generic
if schema.device_class_generic and (
not value.node.device_class
or not any(
value.node.device_class.generic.label == val
for val in schema.device_class_generic
)
):
continue
# check device_class_specific
if value.node.device_class and not check_device_class(
value.node.device_class.specific, schema.device_class_specific
if schema.device_class_specific and (
not value.node.device_class
or not any(
value.node.device_class.specific.label == val
for val in schema.device_class_specific
)
):
continue
@ -1434,15 +1441,3 @@ def check_value(value: ZwaveValue, schema: ZWaveValueDiscoverySchema) -> bool:
if schema.stateful is not None and value.metadata.stateful != schema.stateful:
return False
return True
@callback
def check_device_class(
device_class: DeviceClassItem, required_value: set[str] | None
) -> bool:
"""Check if device class id or label matches."""
if required_value is None:
return True
if any(device_class.label == val for val in required_value):
return True
return False

View File

@ -681,6 +681,12 @@ def central_scene_node_state_fixture():
return json.loads(load_fixture("zwave_js/central_scene_node_state.json"))
@pytest.fixture(name="light_device_class_is_null_state", scope="package")
def light_device_class_is_null_state_fixture():
"""Load node with device class is None state fixture data."""
return json.loads(load_fixture("zwave_js/light_device_class_is_null_state.json"))
# model fixtures
@ -1341,3 +1347,11 @@ def central_scene_node_fixture(client, central_scene_node_state):
node = Node(client, copy.deepcopy(central_scene_node_state))
client.driver.controller.nodes[node.node_id] = node
return node
@pytest.fixture(name="light_device_class_is_null")
def light_device_class_is_null_fixture(client, light_device_class_is_null_state):
"""Mock a node when device class is null."""
node = Node(client, copy.deepcopy(light_device_class_is_null_state))
client.driver.controller.nodes[node.node_id] = node
return node

File diff suppressed because it is too large Load Diff

View File

@ -331,3 +331,15 @@ async def test_indicator_test(
"propertyKey": "Switch",
}
assert args["value"] is False
async def test_light_device_class_is_null(
hass: HomeAssistant, client, light_device_class_is_null, integration
) -> None:
"""Test that a Multilevel Switch CC value with a null device class is discovered as a light.
Tied to #117121.
"""
node = light_device_class_is_null
assert node.device_class is None
assert hass.states.get("light.bar_display_cases")