diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 3333bf6bb3e..a3348ad974d 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -3,7 +3,6 @@ from __future__ import annotations import functools -from typing import Any from zigpy.quirks.v2 import BinarySensorMetadata, EntityMetadata import zigpy.types as t @@ -209,36 +208,6 @@ class IASZone(BinarySensor): """Parse the raw attribute into a bool state.""" return BinarySensor.parse(value & 3) # use only bit 0 and 1 for alarm state - # temporary code to migrate old IasZone sensors to update attribute cache state once - # remove in 2024.4.0 - @property - def extra_state_attributes(self) -> dict[str, Any]: - """Return state attributes.""" - return {"migrated_to_cache": True} # writing new state means we're migrated - - # temporary migration code - @callback - def async_restore_last_state(self, last_state): - """Restore previous state.""" - # trigger migration if extra state attribute is not present - if "migrated_to_cache" not in last_state.attributes: - self.migrate_to_zigpy_cache(last_state) - - # temporary migration code - @callback - def migrate_to_zigpy_cache(self, last_state): - """Save old IasZone sensor state to attribute cache.""" - # previous HA versions did not update the attribute cache for IasZone sensors, so do it once here - # a HA state write is triggered shortly afterwards and writes the "migrated_to_cache" extra state attribute - if last_state.state == STATE_ON: - migrated_state = IasZone.ZoneStatus.Alarm_1 - else: - migrated_state = IasZone.ZoneStatus(0) - - self._cluster_handler.cluster.update_attribute( - IasZone.attributes_by_name[self._attribute_name].id, migrated_state - ) - @STRICT_MATCH(cluster_handler_names=CLUSTER_HANDLER_ZONE, models={"WL4200", "WL4200S"}) class SinopeLeakStatus(BinarySensor): diff --git a/tests/components/zha/test_binary_sensor.py b/tests/components/zha/test_binary_sensor.py index 91a800cafd5..18e78ae7e57 100644 --- a/tests/components/zha/test_binary_sensor.py +++ b/tests/components/zha/test_binary_sensor.py @@ -16,7 +16,6 @@ from .common import ( async_test_rejoin, find_entity_id, send_attributes_report, - update_attribute_cache, ) from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE @@ -151,66 +150,6 @@ async def test_binary_sensor( assert hass.states.get(entity_id).state == STATE_OFF -@pytest.mark.parametrize( - "restored_state", - [ - STATE_ON, - STATE_OFF, - ], -) -async def test_binary_sensor_migration_not_migrated( - hass: HomeAssistant, - zigpy_device_mock, - core_rs, - zha_device_restored, - restored_state, -) -> None: - """Test temporary ZHA IasZone binary_sensor migration to zigpy cache.""" - - entity_id = "binary_sensor.fakemanufacturer_fakemodel_ias_zone" - core_rs(entity_id, state=restored_state, attributes={}) # migration sensor state - await async_mock_load_restore_state_from_storage(hass) - - zigpy_device = zigpy_device_mock(DEVICE_IAS) - - zha_device = await zha_device_restored(zigpy_device) - entity_id = find_entity_id(Platform.BINARY_SENSOR, zha_device, hass) - - assert entity_id is not None - assert hass.states.get(entity_id).state == restored_state - - # confirm migration extra state attribute was set to True - assert hass.states.get(entity_id).attributes["migrated_to_cache"] - - -async def test_binary_sensor_migration_already_migrated( - hass: HomeAssistant, - zigpy_device_mock, - core_rs, - zha_device_restored, -) -> None: - """Test temporary ZHA IasZone binary_sensor migration doesn't migrate multiple times.""" - - entity_id = "binary_sensor.fakemanufacturer_fakemodel_ias_zone" - core_rs(entity_id, state=STATE_OFF, attributes={"migrated_to_cache": True}) - await async_mock_load_restore_state_from_storage(hass) - - zigpy_device = zigpy_device_mock(DEVICE_IAS) - - cluster = zigpy_device.endpoints.get(1).ias_zone - cluster.PLUGGED_ATTR_READS = { - "zone_status": security.IasZone.ZoneStatus.Alarm_1, - } - update_attribute_cache(cluster) - - zha_device = await zha_device_restored(zigpy_device) - entity_id = find_entity_id(Platform.BINARY_SENSOR, zha_device, hass) - - assert entity_id is not None - assert hass.states.get(entity_id).state == STATE_ON # matches attribute cache - assert hass.states.get(entity_id).attributes["migrated_to_cache"] - - @pytest.mark.parametrize( "restored_state", [