Fix invalid alexa climate or water_heater state report with double listed targetSetpoint (#107673)

pull/107730/head
Jan Bouwhuis 2024-01-10 16:23:42 +01:00 committed by GitHub
parent 5bdcbc4e8b
commit de9bb20135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -1112,13 +1112,17 @@ class AlexaThermostatController(AlexaCapability):
"""Return what properties this entity supports."""
properties = [{"name": "thermostatMode"}]
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
if supported & climate.ClimateEntityFeature.TARGET_TEMPERATURE:
if self.entity.domain == climate.DOMAIN:
if supported & climate.ClimateEntityFeature.TARGET_TEMPERATURE_RANGE:
properties.append({"name": "lowerSetpoint"})
properties.append({"name": "upperSetpoint"})
if supported & climate.ClimateEntityFeature.TARGET_TEMPERATURE:
properties.append({"name": "targetSetpoint"})
elif (
self.entity.domain == water_heater.DOMAIN
and supported & water_heater.WaterHeaterEntityFeature.TARGET_TEMPERATURE
):
properties.append({"name": "targetSetpoint"})
if supported & water_heater.WaterHeaterEntityFeature.TARGET_TEMPERATURE:
properties.append({"name": "targetSetpoint"})
if supported & climate.ClimateEntityFeature.TARGET_TEMPERATURE_RANGE:
properties.append({"name": "lowerSetpoint"})
properties.append({"name": "upperSetpoint"})
return properties
def properties_proactively_reported(self) -> bool:

View File

@ -224,9 +224,20 @@ class ReportedProperties:
def assert_equal(self, namespace, name, value):
"""Assert a property is equal to a given value."""
prop_set = None
prop_count = 0
for prop in self.properties:
if prop["namespace"] == namespace and prop["name"] == name:
assert prop["value"] == value
return prop
prop_set = prop
prop_count += 1
if prop_count > 1:
pytest.fail(
f"property {namespace}:{name} more than once in {self.properties!r}"
)
if prop_set:
return prop_set
pytest.fail(f"property {namespace}:{name} not in {self.properties!r}")