Skip to content

Commit

Permalink
Fix invalid alexa climate or water_heater state report with double li…
Browse files Browse the repository at this point in the history
…sted targetSetpoint (#107673)
  • Loading branch information
jbouwh committed Jan 10, 2024
1 parent 5bdcbc4 commit de9bb20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 10 additions & 6 deletions homeassistant/components/alexa/capabilities.py
Expand Up @@ -1112,13 +1112,17 @@ def properties_supported(self) -> list[dict[str, str]]:
"""Return what properties this entity supports."""
properties = [{"name": "thermostatMode"}]
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
if supported & climate.ClimateEntityFeature.TARGET_TEMPERATURE:
properties.append({"name": "targetSetpoint"})
if supported & water_heater.WaterHeaterEntityFeature.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 & climate.ClimateEntityFeature.TARGET_TEMPERATURE_RANGE:
properties.append({"name": "lowerSetpoint"})
properties.append({"name": "upperSetpoint"})
return properties

def properties_proactively_reported(self) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion tests/components/alexa/test_common.py
Expand Up @@ -224,9 +224,20 @@ def assert_not_has_property(self, namespace, name):

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}")

0 comments on commit de9bb20

Please sign in to comment.