From df51e31c9dac39419733bb9bf7032e68953a8895 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Tue, 23 Apr 2024 12:11:04 -0500 Subject: [PATCH] Clamp cloud coverage values to 0 - 100 without logging error --- custom_components/illuminance/sensor.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/custom_components/illuminance/sensor.py b/custom_components/illuminance/sensor.py index 8a24c5c..87f4b03 100644 --- a/custom_components/illuminance/sensor.py +++ b/custom_components/illuminance/sensor.py @@ -411,13 +411,10 @@ def _get_divisor_from_weather_data(self, entity_state: State | None) -> None: if self._entity_status == EntityStatus.OK_CLOUD: try: - cloud = float(condition) - if not 0 <= cloud <= 100: - raise ValueError + cloud = min(max(0, float(condition)), 100) except ValueError: _LOGGER.error( - "%s: Cloud coverage sensor state " - "is not a number between 0 and 100: %s", + "%s: Cloud coverage sensor state is not a number: %s", self.name, condition, )