Skip to content

Commit

Permalink
Merge pull request #38 from olibos/fix/handle-unavailable-ws
Browse files Browse the repository at this point in the history
Fix Kiosk service unavailable make issue with HA Recorder
  • Loading branch information
tijsverkoyen authored Oct 7, 2022
2 parents 6c49793 + afcaea2 commit a87e981
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions custom_components/fusion_solar_kiosk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ async def async_setup(hass: HomeAssistant, config: Config) -> bool:
"""Set up the FusionSolar Kiosk component."""
return True

def isfloat(num) -> bool:
try:
float(num)
return True
except ValueError:
return False

class FusionSolarKioskEnergyEntity(CoordinatorEntity, SensorEntity):
"""Base class for all FusionSolarKioskEnergy entities."""
Expand Down Expand Up @@ -66,6 +72,14 @@ def state(self) -> float:
if entity is not None:
current_value = entity.state
new_value = self.coordinator.data[self._kioskId][ATTR_DATA_REALKPI][self._attribute]
if not isfloat(new_value):
_LOGGER.warning(f'{self.entity_id}: new value ({new_value}) is not a float, so not updating.')
return float(current_value)

if not isfloat(current_value):
_LOGGER.warning(f'{self.entity_id}: current value ({current_value}) is not a float, send 0.')
return 0

if float(new_value) < float(current_value):
_LOGGER.debug(f'{self.entity_id}: new value ({new_value}) is smaller then current value ({entity.state}), so not updating.')
return float(current_value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def getRealTimeKpi(self, id: str):
_LOGGER.debug(jsonData[ATTR_DATA][ATTR_DATA_REALKPI])
return jsonData[ATTR_DATA][ATTR_DATA_REALKPI]

except FusionSolarKioskApiError as error:
except KeyError as error:
_LOGGER.error(error)
_LOGGER.debug(response.text)
_LOGGER.error(response.text)

except FusionSolarKioskApiError as error:
_LOGGER.error(error)
Expand Down

0 comments on commit a87e981

Please sign in to comment.