Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions homeassistant/components/alexa/capabilities.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}")