From d4955a3d870e2f7160dda86b715f4ebad866b510 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 26 Jan 2023 16:51:43 +0100 Subject: [PATCH] Replace assert False by raising an error (#86686) --- homeassistant/components/flux_led/util.py | 2 +- homeassistant/components/http/view.py | 6 +++--- homeassistant/components/izone/climate.py | 2 +- homeassistant/components/recorder/util.py | 6 ++++-- homeassistant/components/wemo/switch.py | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/flux_led/util.py b/homeassistant/components/flux_led/util.py index 6bcf4538dfb..7aa2d91de4e 100644 --- a/homeassistant/components/flux_led/util.py +++ b/homeassistant/components/flux_led/util.py @@ -60,7 +60,7 @@ def _str_to_multi_color_effect(effect_str: str) -> MultiColorEffects: if effect.name.lower() == effect_str: return effect # unreachable due to schema validation - assert False # pragma: no cover + raise RuntimeError # pragma: no cover def _is_zero_rgb_brightness(rgb: tuple[int, int, int]) -> bool: diff --git a/homeassistant/components/http/view.py b/homeassistant/components/http/view.py index 6ab3b2a84a4..6e17f76b629 100644 --- a/homeassistant/components/http/view.py +++ b/homeassistant/components/http/view.py @@ -157,9 +157,9 @@ def request_handler_factory( elif result is None: bresult = b"" else: - assert ( - False - ), f"Result should be None, string, bytes or StreamResponse. Got: {result}" + raise TypeError( + f"Result should be None, string, bytes or StreamResponse. Got: {result}" + ) return web.Response(body=bresult, status=status_code) diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index 59b57f888a7..ee1fe418366 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -293,7 +293,7 @@ class ControllerDevice(ClimateEntity): for (key, value) in self._state_to_pizone.items(): if value == mode: return key - assert False, "Should be unreachable" + raise RuntimeError("Should be unreachable") @property @_return_on_connection_error([]) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index 0e2b1f4d517..fbd1b0c3c93 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -172,7 +172,8 @@ def execute( raise time.sleep(QUERY_RETRY_WAIT) - assert False # unreachable # pragma: no cover + # Unreachable + raise RuntimeError # pragma: no cover def execute_stmt_lambda_element( @@ -206,7 +207,8 @@ def execute_stmt_lambda_element( raise time.sleep(QUERY_RETRY_WAIT) - assert False # unreachable # pragma: no cover + # Unreachable + raise RuntimeError # pragma: no cover def validate_or_move_away_sqlite_database(dburl: str) -> bool: diff --git a/homeassistant/components/wemo/switch.py b/homeassistant/components/wemo/switch.py index 1f9f8bce01f..6d5e6b678b4 100644 --- a/homeassistant/components/wemo/switch.py +++ b/homeassistant/components/wemo/switch.py @@ -116,7 +116,8 @@ class WemoSwitch(WemoBinaryStateEntity, SwitchEntity): if standby_state == StandbyState.STANDBY: return STATE_STANDBY return STATE_UNKNOWN - assert False # Unreachable code statement. + # Unreachable code statement. + raise RuntimeError @property def icon(self) -> str | None: