fix: solar forecast charging

This commit is contained in:
Björn Stormwall
2026-06-23 15:22:05 +02:00
parent 27ed07f0c4
commit d2f7c1dc73
7 changed files with 676 additions and 70 deletions
+17 -4
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import sys
from collections import deque
from datetime import timedelta
from unittest.mock import MagicMock
@@ -39,6 +40,7 @@ for _mod in [
"homeassistant.helpers",
"homeassistant.helpers.device_registry",
"homeassistant.helpers.entity_platform",
"homeassistant.helpers.event",
"homeassistant.helpers.restore_state",
"homeassistant.helpers.selector",
"voluptuous",
@@ -59,7 +61,9 @@ from custom_components.easee_solar_charging.const import ( # noqa: E402
)
CHARGER_ID = "ehxt9pqp"
SOLAR_SENSOR = "sensor.solar_excess"
PRODUCTION_SENSOR = "sensor.solar_production"
HOUSE_SENSOR = "sensor.house_load"
EV_SENSOR = "sensor.ev_charging"
class FakeCoordinator(EaseeSolarCoordinator):
@@ -68,8 +72,16 @@ class FakeCoordinator(EaseeSolarCoordinator):
def __init__(self, options: dict | None = None) -> None:
# Skip DataUpdateCoordinator.__init__ — not needed for logic-only tests.
self.hass = MagicMock()
self.hass.config.time_zone = "UTC"
self.charger_id = CHARGER_ID
self._solar_excess_sensor = SOLAR_SENSOR
self._production_sensor = PRODUCTION_SENSOR
self._house_load_sensor = HOUSE_SENSOR
self._ev_charging_sensor = EV_SENSOR
self._samples: dict = {
PRODUCTION_SENSOR: deque(),
HOUSE_SENSOR: deque(),
EV_SENSOR: deque(),
}
self._device_id = None
self._last_sent_current = None
self._last_sent_at = None
@@ -87,8 +99,9 @@ def coord() -> FakeCoordinator:
return FakeCoordinator()
def make_state(value: str) -> MagicMock:
"""Return a minimal HA state mock with the given state string."""
def make_state(value: str, attributes: dict | None = None) -> MagicMock:
"""Return a minimal HA state mock with the given state string and optional attributes."""
s = MagicMock()
s.state = value
s.attributes = attributes or {}
return s