mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
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:
parent
3bea124d84
commit
9655db3d55
@ -41,7 +41,6 @@ from zwave_js_server.const.command_class.thermostat import (
|
|||||||
THERMOSTAT_SETPOINT_PROPERTY,
|
THERMOSTAT_SETPOINT_PROPERTY,
|
||||||
)
|
)
|
||||||
from zwave_js_server.exceptions import UnknownValueData
|
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.node import Node as ZwaveNode
|
||||||
from zwave_js_server.model.value import (
|
from zwave_js_server.model.value import (
|
||||||
ConfigurationValue,
|
ConfigurationValue,
|
||||||
@ -1235,14 +1234,22 @@ def async_discover_single_value(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# check device_class_generic
|
# check device_class_generic
|
||||||
if value.node.device_class and not check_device_class(
|
if schema.device_class_generic and (
|
||||||
value.node.device_class.generic, schema.device_class_generic
|
not value.node.device_class
|
||||||
|
or not any(
|
||||||
|
value.node.device_class.generic.label == val
|
||||||
|
for val in schema.device_class_generic
|
||||||
|
)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# check device_class_specific
|
# check device_class_specific
|
||||||
if value.node.device_class and not check_device_class(
|
if schema.device_class_specific and (
|
||||||
value.node.device_class.specific, schema.device_class_specific
|
not value.node.device_class
|
||||||
|
or not any(
|
||||||
|
value.node.device_class.specific.label == val
|
||||||
|
for val in schema.device_class_specific
|
||||||
|
)
|
||||||
):
|
):
|
||||||
continue
|
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:
|
if schema.stateful is not None and value.metadata.stateful != schema.stateful:
|
||||||
return False
|
return False
|
||||||
return True
|
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
|
|
||||||
|
@ -681,6 +681,12 @@ def central_scene_node_state_fixture():
|
|||||||
return json.loads(load_fixture("zwave_js/central_scene_node_state.json"))
|
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
|
# 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))
|
node = Node(client, copy.deepcopy(central_scene_node_state))
|
||||||
client.driver.controller.nodes[node.node_id] = node
|
client.driver.controller.nodes[node.node_id] = node
|
||||||
return 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
|
||||||
|
10611
tests/components/zwave_js/fixtures/light_device_class_is_null_state.json
Normal file
10611
tests/components/zwave_js/fixtures/light_device_class_is_null_state.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -331,3 +331,15 @@ async def test_indicator_test(
|
|||||||
"propertyKey": "Switch",
|
"propertyKey": "Switch",
|
||||||
}
|
}
|
||||||
assert args["value"] is False
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user