mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +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 import device_registry as dr
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
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 homeassistant.helpers.event import async_track_time_interval
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -204,7 +204,7 @@ class FroniusSolarNet:
|
|||||||
|
|
||||||
# Only for re-scans. Initial setup adds entities through sensor.async_setup_entry
|
# Only for re-scans. Initial setup adds entities through sensor.async_setup_entry
|
||||||
if self.config_entry.state == ConfigEntryState.LOADED:
|
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(
|
_LOGGER.debug(
|
||||||
"New inverter added (UID: %s)",
|
"New inverter added (UID: %s)",
|
||||||
|
@ -661,7 +661,7 @@ class _FroniusSensorEntity(CoordinatorEntity["FroniusCoordinatorBase"], SensorEn
|
|||||||
if new_value is None:
|
if new_value is None:
|
||||||
return self.entity_description.default_value
|
return self.entity_description.default_value
|
||||||
if self.entity_description.invalid_when_falsy and not new_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):
|
if isinstance(new_value, float):
|
||||||
return round(new_value, 4)
|
return round(new_value, 4)
|
||||||
return new_value
|
return new_value
|
||||||
@ -671,10 +671,9 @@ class _FroniusSensorEntity(CoordinatorEntity["FroniusCoordinatorBase"], SensorEn
|
|||||||
"""Handle updated data from the coordinator."""
|
"""Handle updated data from the coordinator."""
|
||||||
try:
|
try:
|
||||||
self._attr_native_value = self._get_entity_value()
|
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
|
# 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
|
# 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._attr_native_value = self.entity_description.default_value
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user