Skip to content

Commit

Permalink
Fix TypeError if power value is None from moonraker (#349)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc-Olivier Arsenault <[email protected]>
  • Loading branch information
linw1995 and marcolivierarsenault authored May 31, 2024
1 parent 5a4c1ff commit 79a2022
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 79a2022

Please sign in to comment.