From 79a2022935f2b01444cbe4a384a424cc09aa7c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Sat, 1 Jun 2024 02:26:54 +0800 Subject: [PATCH] Fix TypeError if power value is None from moonraker (#349) Co-authored-by: Marc-Olivier Arsenault --- custom_components/moonraker/sensor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index ef47609..2731300 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -423,7 +423,10 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): status_key=obj, name=f"{split_obj[1].replace('_', ' ')} Power".title(), value_fn=lambda sensor: int( - sensor.coordinator.data["status"][sensor.status_key]["power"] * 100 + ( + sensor.coordinator.data["status"][sensor.status_key]["power"] + or 0.0 + ) * 100 ), subscriptions=[(obj, "power")], icon="mdi:flash", @@ -502,7 +505,10 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): status_key=obj, name=f"{base_name} Power".title(), value_fn=lambda sensor: int( - sensor.coordinator.data["status"][sensor.status_key]["power"] * 100 + ( + sensor.coordinator.data["status"][sensor.status_key]["power"] + or 0.0 + ) * 100 ), subscriptions=[(obj, "power")], icon="mdi:flash",