Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Die Einrichtung laeuft komplett ueber die Home-Assistant-Oberflaeche. YAML ist nicht noetig.

Version `1.0.1` ist mit Home Assistant `2026.8` kompatibel und gegen `2026.8.1`
Version `1.0.2` ist mit Home Assistant `2026.8` kompatibel und gegen `2026.8.1`
getestet.

## Was Macht Die Integration?
Expand Down
11 changes: 6 additions & 5 deletions custom_components/pv_device_split/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ def async_schedule_power_discovery(hass: HomeAssistant) -> None:
@callback
def async_schedule_power_discovery_retries(hass: HomeAssistant) -> None:
"""Schedule several scans while Home Assistant finishes restoring states."""

@callback
def _schedule_retry(_now: object) -> None:
async_schedule_power_discovery(hass)

for delay in (5, 30, 120):
async_call_later(
hass,
delay,
lambda now: async_schedule_power_discovery(hass),
)
async_call_later(hass, delay, _schedule_retry)


async def _async_discover_power_pair(hass: HomeAssistant) -> None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/pv_device_split/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/dr-apple/Solar-Load-Split/issues",
"requirements": [],
"version": "1.0.1"
"version": "1.0.2"
}
25 changes: 24 additions & 1 deletion tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for the Solar Load Split config and options flows."""

from unittest.mock import patch
from unittest.mock import Mock, patch

from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
Expand All @@ -15,6 +15,9 @@
CONF_INVERT_GRID,
DOMAIN,
)
from custom_components.pv_device_split.discovery import (
async_schedule_power_discovery_retries,
)


def _data(device: str, grid: str = "sensor.grid_power") -> dict:
Expand Down Expand Up @@ -81,3 +84,23 @@ async def test_options_rejects_duplicate_pair(
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "already_configured"}
assert edited.unique_id == "sensor.old_sensor.grid_power"


def test_discovery_retries_use_callback_jobs(hass: HomeAssistant) -> None:
"""Delayed discovery callbacks stay on Home Assistant's event loop."""
scheduled: list[object] = []

with patch(
"custom_components.pv_device_split.discovery.async_call_later",
side_effect=lambda _hass, _delay, action: scheduled.append(action),
):
async_schedule_power_discovery_retries(hass)

assert len(scheduled) == 3
assert all(getattr(action, "_hass_callback", False) for action in scheduled)

with patch(
"custom_components.pv_device_split.discovery.async_schedule_power_discovery"
) as discover:
scheduled[0](Mock())
discover.assert_called_once_with(hass)
Loading