Skip to content

Commit

Permalink
Merge e285bd1 into f2cf105
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Jul 28, 2022
2 parents f2cf105 + e285bd1 commit 4e35cd1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/powercalc/sensors/power.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from decimal import Decimal
from decimal import Decimal, DecimalException
from typing import Optional, cast

import homeassistant.helpers.entity_registry as er
Expand Down Expand Up @@ -444,7 +444,11 @@ async def calculate_power(self, state: State) -> Optional[Decimal]:
standby_power *= Decimal(self._multiply_factor)
power += standby_power

return Decimal(power)
try:
return Decimal(power)
except DecimalException:
_LOGGER.error(f"{state.entity_id}: Could not convert value '{power}' to decimal")
return None

async def is_calculation_enabled(self) -> bool:
if CONF_CALCULATION_ENABLED_CONDITION not in self._sensor_config:
Expand Down

0 comments on commit 4e35cd1

Please sign in to comment.