Fix Z-Wave JS discovery schema for thermostat devices (#47087)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Marcel van der Veldt 2021-02-26 20:19:23 +01:00 committed by GitHub
parent 8971ab2edc
commit 7ca148f65d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,6 +75,8 @@ class ZWaveDiscoverySchema:
device_class_specific: Optional[Set[Union[str, int]]] = None
# [optional] additional values that ALL need to be present on the node for this scheme to pass
required_values: Optional[List[ZWaveValueDiscoverySchema]] = None
# [optional] additional values that MAY NOT be present on the node for this scheme to pass
absent_values: Optional[List[ZWaveValueDiscoverySchema]] = None
# [optional] bool to specify if this primary value may be discovered by multiple platforms
allow_multi: bool = False
@ -186,36 +188,30 @@ DISCOVERY_SCHEMAS = [
),
),
# climate
# thermostats supporting mode (and optional setpoint)
ZWaveDiscoverySchema(
platform="climate",
device_class_generic={"Thermostat"},
device_class_specific={
"Setback Thermostat",
"Thermostat General",
"Thermostat General V2",
"General Thermostat",
"General Thermostat V2",
},
primary_value=ZWaveValueDiscoverySchema(
command_class={CommandClass.THERMOSTAT_MODE},
property={"mode"},
type={"number"},
),
),
# climate
# setpoint thermostats
# thermostats supporting setpoint only (and thus not mode)
ZWaveDiscoverySchema(
platform="climate",
device_class_generic={"Thermostat"},
device_class_specific={
"Setpoint Thermostat",
"Unused",
},
primary_value=ZWaveValueDiscoverySchema(
command_class={CommandClass.THERMOSTAT_SETPOINT},
property={"setpoint"},
type={"number"},
),
absent_values=[ # mode must not be present to prevent dupes
ZWaveValueDiscoverySchema(
command_class={CommandClass.THERMOSTAT_MODE},
property={"mode"},
type={"number"},
),
],
),
# binary sensors
ZWaveDiscoverySchema(
@ -436,6 +432,13 @@ def async_discover_values(node: ZwaveNode) -> Generator[ZwaveDiscoveryInfo, None
for val_scheme in schema.required_values
):
continue
# check for values that may not be present
if schema.absent_values is not None:
if any(
any(check_value(val, val_scheme) for val in node.values.values())
for val_scheme in schema.absent_values
):
continue
# all checks passed, this value belongs to an entity
yield ZwaveDiscoveryInfo(
node=value.node,