Netatmo: do not fail on schedule updates (#142933)

* do not fail on schedule updates

* add test to check that the store data remains unchanged
This commit is contained in:
wuede 2025-05-18 23:00:36 +02:00 committed by GitHub
parent 3d83c6299b
commit 541b969d3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 13 deletions

View File

@ -248,19 +248,22 @@ class NetatmoThermostat(NetatmoRoomEntity, ClimateEntity):
if self.home.entity_id != data["home_id"]:
return
if data["event_type"] == EVENT_TYPE_SCHEDULE and "schedule_id" in data:
self._selected_schedule = getattr(
self.hass.data[DOMAIN][DATA_SCHEDULES][self.home.entity_id].get(
data["schedule_id"]
),
"name",
None,
)
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
self._selected_schedule
)
self.async_write_ha_state()
self.data_handler.async_force_update(self._signal_name)
if data["event_type"] == EVENT_TYPE_SCHEDULE:
# handle schedule change
if "schedule_id" in data:
self._selected_schedule = getattr(
self.hass.data[DOMAIN][DATA_SCHEDULES][self.home.entity_id].get(
data["schedule_id"]
),
"name",
None,
)
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
self._selected_schedule
)
self.async_write_ha_state()
self.data_handler.async_force_update(self._signal_name)
# ignore other schedule events
return
home = data["home"]

View File

@ -66,6 +66,34 @@ async def test_entity(
)
async def test_schedule_update_webhook_event(
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
) -> None:
"""Test schedule update webhook event without schedule_id."""
with selected_platforms([Platform.CLIMATE]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
webhook_id = config_entry.data[CONF_WEBHOOK_ID]
climate_entity_livingroom = "climate.livingroom"
# Save initial state
initial_state = hass.states.get(climate_entity_livingroom)
# Create a schedule update event without a schedule_id (the event is sent when temperature sets of a schedule are changed)
response = {
"home_id": "91763b24c43d3e344f424e8b",
"event_type": "schedule",
"push_type": "home_event_changed",
}
await simulate_webhook(hass, webhook_id, response)
# State should be unchanged
assert hass.states.get(climate_entity_livingroom) == initial_state
async def test_webhook_event_handling_thermostats(
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
) -> None: