From ffc3560dad6761bece88ee43b0a97900ce8fa2b3 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 24 May 2024 14:56:57 -0400 Subject: [PATCH] Remove unneeded asserts (#118056) * Remove unneeded asserts * No need to guard changing a timer that is owned by a disconnected device --- homeassistant/components/intent/timers.py | 24 ---------------- tests/components/intent/test_timers.py | 35 ----------------------- 2 files changed, 59 deletions(-) diff --git a/homeassistant/components/intent/timers.py b/homeassistant/components/intent/timers.py index 1c41d9aa0df..3b7cf8813a9 100644 --- a/homeassistant/components/intent/timers.py +++ b/homeassistant/components/intent/timers.py @@ -286,9 +286,6 @@ class TimerManager: if timer is None: raise TimerNotFoundError - if not self.is_timer_device(timer.device_id): - raise TimersNotSupportedError(timer.device_id) - if timer.is_active: task = self.timer_tasks.pop(timer_id) task.cancel() @@ -310,9 +307,6 @@ class TimerManager: if timer is None: raise TimerNotFoundError - if not self.is_timer_device(timer.device_id): - raise TimersNotSupportedError(timer.device_id) - if seconds == 0: # Don't bother cancelling and recreating the timer task return @@ -355,9 +349,6 @@ class TimerManager: if timer is None: raise TimerNotFoundError - if not self.is_timer_device(timer.device_id): - raise TimersNotSupportedError(timer.device_id) - if not timer.is_active: # Already paused return @@ -381,9 +372,6 @@ class TimerManager: if timer is None: raise TimerNotFoundError - if not self.is_timer_device(timer.device_id): - raise TimersNotSupportedError(timer.device_id) - if timer.is_active: # Already unpaused return @@ -783,8 +771,6 @@ class CancelTimerIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - timer = _find_timer(hass, intent_obj.device_id, slots) timer_manager.cancel_timer(timer.id) return intent_obj.create_response() @@ -814,8 +800,6 @@ class IncreaseTimerIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - total_seconds = _get_total_seconds(slots) timer = _find_timer(hass, intent_obj.device_id, slots) timer_manager.add_time(timer.id, total_seconds) @@ -846,8 +830,6 @@ class DecreaseTimerIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - total_seconds = _get_total_seconds(slots) timer = _find_timer(hass, intent_obj.device_id, slots) timer_manager.remove_time(timer.id, total_seconds) @@ -877,8 +859,6 @@ class PauseTimerIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - timer = _find_timer(hass, intent_obj.device_id, slots) timer_manager.pause_timer(timer.id) return intent_obj.create_response() @@ -907,8 +887,6 @@ class UnpauseTimerIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - timer = _find_timer(hass, intent_obj.device_id, slots) timer_manager.unpause_timer(timer.id) return intent_obj.create_response() @@ -937,8 +915,6 @@ class TimerStatusIntentHandler(intent.IntentHandler): # Fail early raise TimersNotSupportedError(intent_obj.device_id) - assert intent_obj.device_id is not None - statuses: list[dict[str, Any]] = [] for timer in _find_timers(hass, intent_obj.device_id, slots): total_seconds = timer.seconds_left diff --git a/tests/components/intent/test_timers.py b/tests/components/intent/test_timers.py index 46e8548bee6..d017713bb1d 100644 --- a/tests/components/intent/test_timers.py +++ b/tests/components/intent/test_timers.py @@ -971,41 +971,6 @@ async def test_timers_not_supported(hass: HomeAssistant) -> None: language=hass.config.language, ) - # Start a timer - @callback - def handle_timer(event_type: TimerEventType, timer: TimerInfo) -> None: - pass - - device_id = "test_device" - unregister = timer_manager.register_handler(device_id, handle_timer) - - timer_id = timer_manager.start_timer( - device_id, - hours=None, - minutes=5, - seconds=None, - language=hass.config.language, - ) - - # Unregister handler so device no longer "supports" timers - unregister() - - # All operations on the timer should fail now - with pytest.raises(TimersNotSupportedError): - timer_manager.add_time(timer_id, 1) - - with pytest.raises(TimersNotSupportedError): - timer_manager.remove_time(timer_id, 1) - - with pytest.raises(TimersNotSupportedError): - timer_manager.pause_timer(timer_id) - - with pytest.raises(TimersNotSupportedError): - timer_manager.unpause_timer(timer_id) - - with pytest.raises(TimersNotSupportedError): - timer_manager.cancel_timer(timer_id) - async def test_timer_status_with_names(hass: HomeAssistant, init_components) -> None: """Test getting the status of named timers."""