Skip to content

Commit

Permalink
FIX error when production value is None
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Aug 2, 2023
1 parent dd07ef6 commit b0bd57b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions custom_components/solar_optimizer/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ async def _async_update_data(self):

# Add a power_consumption and power_production
power_production = get_safe_float(self.hass, self._power_production_entity_id)
if not power_production:
_LOGGER.warning(
"Power production is not valued. Solar Optimizer will be disabled"
)
return None

if not self._smooth_production:
calculated_data["power_production"] = power_production
else:
Expand Down
6 changes: 4 additions & 2 deletions custom_components/solar_optimizer/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def __init__(self, coordinator, hass, idx):
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_native_value = self.coordinator.data[self.idx]
self.async_write_ha_state()
value = self.coordinator.data.get(self.idx)
if value:
self._attr_native_value = value
self.async_write_ha_state()

@property
def device_info(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solar_optimizer/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def _handle_coordinator_update(self) -> None:
return
device: ManagedDevice = self.coordinator.data.get(self.idx)
if not device:
_LOGGER.warning("No device %s found ...", self.idx)
# it is possible to not have device in coordinator update (if device is not enabled)
_LOGGER.debug("No device %s found ...", self.idx)
return

self._attr_is_on = device.is_active
Expand Down

0 comments on commit b0bd57b

Please sign in to comment.