mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Fix Fronius entity initialisation (#103211)
* Use None instead of raising ValueError if value invalid * use async_dispatcher_send
This commit is contained in:
parent
47d6d6c344
commit
76115ce766
@ -16,7 +16,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
from .const import (
|
||||
@ -204,7 +204,7 @@ class FroniusSolarNet:
|
||||
|
||||
# Only for re-scans. Initial setup adds entities through sensor.async_setup_entry
|
||||
if self.config_entry.state == ConfigEntryState.LOADED:
|
||||
dispatcher_send(self.hass, SOLAR_NET_DISCOVERY_NEW, _coordinator)
|
||||
async_dispatcher_send(self.hass, SOLAR_NET_DISCOVERY_NEW, _coordinator)
|
||||
|
||||
_LOGGER.debug(
|
||||
"New inverter added (UID: %s)",
|
||||
|
@ -661,7 +661,7 @@ class _FroniusSensorEntity(CoordinatorEntity["FroniusCoordinatorBase"], SensorEn
|
||||
if new_value is None:
|
||||
return self.entity_description.default_value
|
||||
if self.entity_description.invalid_when_falsy and not new_value:
|
||||
raise ValueError(f"Ignoring zero value for {self.entity_id}.")
|
||||
return None
|
||||
if isinstance(new_value, float):
|
||||
return round(new_value, 4)
|
||||
return new_value
|
||||
@ -671,10 +671,9 @@ class _FroniusSensorEntity(CoordinatorEntity["FroniusCoordinatorBase"], SensorEn
|
||||
"""Handle updated data from the coordinator."""
|
||||
try:
|
||||
self._attr_native_value = self._get_entity_value()
|
||||
except (KeyError, ValueError):
|
||||
except KeyError:
|
||||
# sets state to `None` if no default_value is defined in entity description
|
||||
# KeyError: raised when omitted in response - eg. at night when no production
|
||||
# ValueError: raised when invalid zero value received
|
||||
self._attr_native_value = self.entity_description.default_value
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user