diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9f2a6..3ec73cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## 1.0.2 (Unreleased) +## 1.1.0 (Unreleased) ### Bugfixes - Removes `device_class=temperature` restriction when picking your temperature sensor. (Issue#1)[https://github.com/SourceLabOrg/HomeAssistant-PVOutputPublisher/issues/1] +### Feature Changes +- Switched to strict, clock-aligned scheduling to prevent time drift and perfectly sync with PVOutput intervals. (Issue#1)[https://github.com/SourceLabOrg/HomeAssistant-PVOutputPublisher/issues/1] + ## 1.0.1 (03/23/2026) Setup and submitted to HACs! diff --git a/custom_components/pvoutput_publisher/__init__.py b/custom_components/pvoutput_publisher/__init__.py index 4c44920..7c2edce 100644 --- a/custom_components/pvoutput_publisher/__init__.py +++ b/custom_components/pvoutput_publisher/__init__.py @@ -5,7 +5,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.const import Platform -from homeassistant.helpers.event import async_track_time_interval +from homeassistant.helpers.event import async_track_time_change from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.dispatcher import async_dispatcher_send import homeassistant.util.dt as dt_util @@ -147,7 +147,22 @@ async def push_data(now: datetime, sys_id=system_id, gen_id=generation_ent_id, c except Exception as e: _LOGGER.error("Unexpected error connecting to PVOutput for %s: %s", name, e) - listener = async_track_time_interval(hass, push_data, timedelta(minutes=frequency)) + # Smart clock-aligned scheduling (Cron style) + if frequency < 60: + # Creates a list of exact minutes: [0, 5, 10, 15...] + minutes = list(range(0, 60, frequency)) + listener = async_track_time_change(hass, push_data, minute=minutes, second=0) + elif frequency == 60: + # Every hour on the dot (xx:00:00) + listener = async_track_time_change(hass, push_data, minute=0, second=0) + elif frequency == 180: + # Every 3 hours on the dot (00:00, 03:00, 06:00...) + hours = list(range(0, 24, 3)) + listener = async_track_time_change(hass, push_data, hour=hours, minute=0, second=0) + else: + # Safe fallback just in case + listener = async_track_time_change(hass, push_data, minute=list(range(0, 60, 5)), second=0) + remove_listeners.append(listener) hass.data[DOMAIN][entry.entry_id] = remove_listeners diff --git a/custom_components/pvoutput_publisher/manifest.json b/custom_components/pvoutput_publisher/manifest.json index 29bf985..fe45bbc 100644 --- a/custom_components/pvoutput_publisher/manifest.json +++ b/custom_components/pvoutput_publisher/manifest.json @@ -9,5 +9,5 @@ "iot_class": "cloud_push", "issue_tracker": "https://github.com/SourceLabOrg/HomeAssistant-PVOutputPublisher/issues", "requirements": [], - "version": "1.0.2" + "version": "1.1.0" }