Remove unneeded asserts (#118056)

* Remove unneeded asserts

* No need to guard changing a timer that is owned by a disconnected device
pull/117875/head
Paulus Schoutsen 2024-05-24 14:56:57 -04:00 committed by GitHub
parent 5be15c94bc
commit ffc3560dad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 59 deletions

View File

@ -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

View File

@ -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."""