mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Remove unneeded asserts (#118056)
* Remove unneeded asserts * No need to guard changing a timer that is owned by a disconnected device
This commit is contained in:
parent
5be15c94bc
commit
ffc3560dad
@ -286,9 +286,6 @@ class TimerManager:
|
|||||||
if timer is None:
|
if timer is None:
|
||||||
raise TimerNotFoundError
|
raise TimerNotFoundError
|
||||||
|
|
||||||
if not self.is_timer_device(timer.device_id):
|
|
||||||
raise TimersNotSupportedError(timer.device_id)
|
|
||||||
|
|
||||||
if timer.is_active:
|
if timer.is_active:
|
||||||
task = self.timer_tasks.pop(timer_id)
|
task = self.timer_tasks.pop(timer_id)
|
||||||
task.cancel()
|
task.cancel()
|
||||||
@ -310,9 +307,6 @@ class TimerManager:
|
|||||||
if timer is None:
|
if timer is None:
|
||||||
raise TimerNotFoundError
|
raise TimerNotFoundError
|
||||||
|
|
||||||
if not self.is_timer_device(timer.device_id):
|
|
||||||
raise TimersNotSupportedError(timer.device_id)
|
|
||||||
|
|
||||||
if seconds == 0:
|
if seconds == 0:
|
||||||
# Don't bother cancelling and recreating the timer task
|
# Don't bother cancelling and recreating the timer task
|
||||||
return
|
return
|
||||||
@ -355,9 +349,6 @@ class TimerManager:
|
|||||||
if timer is None:
|
if timer is None:
|
||||||
raise TimerNotFoundError
|
raise TimerNotFoundError
|
||||||
|
|
||||||
if not self.is_timer_device(timer.device_id):
|
|
||||||
raise TimersNotSupportedError(timer.device_id)
|
|
||||||
|
|
||||||
if not timer.is_active:
|
if not timer.is_active:
|
||||||
# Already paused
|
# Already paused
|
||||||
return
|
return
|
||||||
@ -381,9 +372,6 @@ class TimerManager:
|
|||||||
if timer is None:
|
if timer is None:
|
||||||
raise TimerNotFoundError
|
raise TimerNotFoundError
|
||||||
|
|
||||||
if not self.is_timer_device(timer.device_id):
|
|
||||||
raise TimersNotSupportedError(timer.device_id)
|
|
||||||
|
|
||||||
if timer.is_active:
|
if timer.is_active:
|
||||||
# Already unpaused
|
# Already unpaused
|
||||||
return
|
return
|
||||||
@ -783,8 +771,6 @@ class CancelTimerIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
timer = _find_timer(hass, intent_obj.device_id, slots)
|
timer = _find_timer(hass, intent_obj.device_id, slots)
|
||||||
timer_manager.cancel_timer(timer.id)
|
timer_manager.cancel_timer(timer.id)
|
||||||
return intent_obj.create_response()
|
return intent_obj.create_response()
|
||||||
@ -814,8 +800,6 @@ class IncreaseTimerIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
total_seconds = _get_total_seconds(slots)
|
total_seconds = _get_total_seconds(slots)
|
||||||
timer = _find_timer(hass, intent_obj.device_id, slots)
|
timer = _find_timer(hass, intent_obj.device_id, slots)
|
||||||
timer_manager.add_time(timer.id, total_seconds)
|
timer_manager.add_time(timer.id, total_seconds)
|
||||||
@ -846,8 +830,6 @@ class DecreaseTimerIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
total_seconds = _get_total_seconds(slots)
|
total_seconds = _get_total_seconds(slots)
|
||||||
timer = _find_timer(hass, intent_obj.device_id, slots)
|
timer = _find_timer(hass, intent_obj.device_id, slots)
|
||||||
timer_manager.remove_time(timer.id, total_seconds)
|
timer_manager.remove_time(timer.id, total_seconds)
|
||||||
@ -877,8 +859,6 @@ class PauseTimerIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
timer = _find_timer(hass, intent_obj.device_id, slots)
|
timer = _find_timer(hass, intent_obj.device_id, slots)
|
||||||
timer_manager.pause_timer(timer.id)
|
timer_manager.pause_timer(timer.id)
|
||||||
return intent_obj.create_response()
|
return intent_obj.create_response()
|
||||||
@ -907,8 +887,6 @@ class UnpauseTimerIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
timer = _find_timer(hass, intent_obj.device_id, slots)
|
timer = _find_timer(hass, intent_obj.device_id, slots)
|
||||||
timer_manager.unpause_timer(timer.id)
|
timer_manager.unpause_timer(timer.id)
|
||||||
return intent_obj.create_response()
|
return intent_obj.create_response()
|
||||||
@ -937,8 +915,6 @@ class TimerStatusIntentHandler(intent.IntentHandler):
|
|||||||
# Fail early
|
# Fail early
|
||||||
raise TimersNotSupportedError(intent_obj.device_id)
|
raise TimersNotSupportedError(intent_obj.device_id)
|
||||||
|
|
||||||
assert intent_obj.device_id is not None
|
|
||||||
|
|
||||||
statuses: list[dict[str, Any]] = []
|
statuses: list[dict[str, Any]] = []
|
||||||
for timer in _find_timers(hass, intent_obj.device_id, slots):
|
for timer in _find_timers(hass, intent_obj.device_id, slots):
|
||||||
total_seconds = timer.seconds_left
|
total_seconds = timer.seconds_left
|
||||||
|
@ -971,41 +971,6 @@ async def test_timers_not_supported(hass: HomeAssistant) -> None:
|
|||||||
language=hass.config.language,
|
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:
|
async def test_timer_status_with_names(hass: HomeAssistant, init_components) -> None:
|
||||||
"""Test getting the status of named timers."""
|
"""Test getting the status of named timers."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user