@@ -1161,3 +1161,69 @@ async def test_cover_state_restoration(
11611161 assert entity .state ["state" ] == interim_state
11621162 await asyncio .sleep (DEFAULT_MOVEMENT_TIMEOUT )
11631163 assert entity .state ["state" ] == final_state
1164+
1165+
1166+ async def test_cover_lift_timer_cancellation_on_remove (zha_gateway : Gateway ) -> None :
1167+ """Test the cover timer handle cancellation upon removal."""
1168+
1169+ # create mock cover device
1170+ zha_device , zigpy_cover_device = await device_cover_mock (
1171+ zha_gateway ,
1172+ current_position_lift_percentage = 0 ,
1173+ current_position_tilt_percentage = 0 ,
1174+ window_covering_type = WCT .Tilt_blind_tilt_and_lift ,
1175+ )
1176+
1177+ # start lift close timer
1178+ entity = get_entity (zha_device , platform = Platform .COVER )
1179+ with patch ("zigpy.zcl.Cluster.request" , return_value = [0x1 , zcl_f .Status .SUCCESS ]):
1180+ await entity .async_close_cover ()
1181+ await zha_gateway .async_block_till_done ()
1182+ assert entity .state ["state" ] == CoverState .CLOSING
1183+
1184+ # remove entity
1185+ await entity .on_remove ()
1186+
1187+
1188+ async def test_cover_tilt_timer_cancellation_on_remove (zha_gateway : Gateway ) -> None :
1189+ """Test the cover timer handle cancellation upon removal."""
1190+
1191+ # create mock cover device
1192+ zha_device , zigpy_cover_device = await device_cover_mock (
1193+ zha_gateway ,
1194+ current_position_lift_percentage = 0 ,
1195+ current_position_tilt_percentage = 0 ,
1196+ window_covering_type = WCT .Tilt_blind_tilt_and_lift ,
1197+ )
1198+
1199+ # start tilt close timer
1200+ entity = get_entity (zha_device , platform = Platform .COVER )
1201+ with patch ("zigpy.zcl.Cluster.request" , return_value = [0x1 , zcl_f .Status .SUCCESS ]):
1202+ await entity .async_close_cover_tilt ()
1203+ await zha_gateway .async_block_till_done ()
1204+ assert entity .state ["state" ] == CoverState .CLOSING
1205+
1206+ # remove entity
1207+ await entity .on_remove ()
1208+
1209+
1210+ async def test_cover_state_restore_timer_cancellation_on_remove (
1211+ zha_gateway : Gateway ,
1212+ ) -> None :
1213+ """Test the cover timer handle cancellation upon removal."""
1214+
1215+ # create mock cover device
1216+ zha_device , zigpy_cover_device = await device_cover_mock (
1217+ zha_gateway ,
1218+ current_position_lift_percentage = 0 ,
1219+ current_position_tilt_percentage = 0 ,
1220+ window_covering_type = WCT .Tilt_blind_tilt_and_lift ,
1221+ )
1222+
1223+ # start state restore timer
1224+ entity = get_entity (zha_device , platform = Platform .COVER )
1225+ entity .restore_external_state_attributes (state = CoverState .CLOSING )
1226+ assert entity .state ["state" ] == CoverState .CLOSING
1227+
1228+ # remove entity
1229+ await entity .on_remove ()
0 commit comments