Skip to content
Snippets Groups Projects
Unverified Commit e32694c1 authored by Eric Svärd's avatar Eric Svärd Committed by GitHub
Browse files

Make SolarEdge energy value validation a bit less aggressive (#69998)

* Make energy value validation a bit less aggressive

Attempt to solve issue 69600 introduced by previous fix for issue
59285.

- Introduce a tolerance factor for energy value validation.
- Only skip update the specific invalid energy entity. An energy entity
  with invalid values will now show "State unknown".

* Remove the tolerance factor. Let's just ignore the specific invalid energy entity.
parent 5167535b
No related branches found
No related tags found
No related merge requests found
...@@ -94,8 +94,10 @@ class SolarEdgeOverviewDataService(SolarEdgeDataService): ...@@ -94,8 +94,10 @@ class SolarEdgeOverviewDataService(SolarEdgeDataService):
for index, key in enumerate(energy_keys, start=1): for index, key in enumerate(energy_keys, start=1):
# All coming values in list should be larger than the current value. # All coming values in list should be larger than the current value.
if any(self.data[k] > self.data[key] for k in energy_keys[index:]): if any(self.data[k] > self.data[key] for k in energy_keys[index:]):
self.data = {} LOGGER.info(
raise UpdateFailed("Invalid energy values, skipping update") "Ignoring invalid energy value %s for %s", self.data[key], key
)
self.data.pop(key)
LOGGER.debug("Updated SolarEdge overview: %s", self.data) LOGGER.debug("Updated SolarEdge overview: %s", self.data)
......
...@@ -6,8 +6,9 @@ from homeassistant.components.solaredge.const import ( ...@@ -6,8 +6,9 @@ from homeassistant.components.solaredge.const import (
DEFAULT_NAME, DEFAULT_NAME,
DOMAIN, DOMAIN,
OVERVIEW_UPDATE_DELAY, OVERVIEW_UPDATE_DELAY,
SENSOR_TYPES,
) )
from homeassistant.const import CONF_API_KEY, CONF_NAME, STATE_UNAVAILABLE from homeassistant.const import CONF_API_KEY, CONF_NAME, STATE_UNKNOWN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
...@@ -29,6 +30,9 @@ async def test_solaredgeoverviewdataservice_energy_values_validity( ...@@ -29,6 +30,9 @@ async def test_solaredgeoverviewdataservice_energy_values_validity(
) )
mock_solaredge().get_details.return_value = {"details": {"status": "active"}} mock_solaredge().get_details.return_value = {"details": {"status": "active"}}
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
for description in SENSOR_TYPES:
description.entity_registry_enabled_default = True
await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.config_entries.async_setup(mock_config_entry.entry_id)
# Valid energy values update # Valid energy values update
...@@ -56,7 +60,7 @@ async def test_solaredgeoverviewdataservice_energy_values_validity( ...@@ -56,7 +60,7 @@ async def test_solaredgeoverviewdataservice_energy_values_validity(
state = hass.states.get("sensor.solaredge_lifetime_energy") state = hass.states.get("sensor.solaredge_lifetime_energy")
assert state assert state
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNKNOWN
# New valid energy values update # New valid energy values update
mock_overview_data["overview"]["lifeTimeData"]["energy"] = 100001 mock_overview_data["overview"]["lifeTimeData"]["energy"] = 100001
...@@ -74,9 +78,13 @@ async def test_solaredgeoverviewdataservice_energy_values_validity( ...@@ -74,9 +78,13 @@ async def test_solaredgeoverviewdataservice_energy_values_validity(
async_fire_time_changed(hass, dt_util.utcnow() + OVERVIEW_UPDATE_DELAY) async_fire_time_changed(hass, dt_util.utcnow() + OVERVIEW_UPDATE_DELAY)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("sensor.solaredge_lifetime_energy") state = hass.states.get("sensor.solaredge_energy_this_year")
assert state
assert state.state == STATE_UNKNOWN
# Check that the valid lastMonthData is still available
state = hass.states.get("sensor.solaredge_energy_this_month")
assert state assert state
assert state.state == STATE_UNAVAILABLE assert state.state == str(mock_overview_data["overview"]["lastMonthData"]["energy"])
# All zero energy values should also be valid. # All zero energy values should also be valid.
mock_overview_data["overview"]["lifeTimeData"]["energy"] = 0.0 mock_overview_data["overview"]["lifeTimeData"]["energy"] = 0.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment