Skip to content

Commit 4956b71

Browse files
authored
Merge pull request #6 from ngoviet/feat/all-day-data
Fetch a day's statistics in one getAllDayData request, with slot-keyed series maths and a normalised battery mapping. Validated through the no-mistakes gate: 15 review rounds, tests, docs and lint.
2 parents 09ccff8 + 7f9313e commit 4956b71

19 files changed

Lines changed: 10161 additions & 275 deletions

‎__init__.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636

3737
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.BINARY_SENSOR]
3838

39+
# Delay before the monthly/yearly/total coordinators are warmed, so the backfill
40+
# that the daily coordinator kicks off has time to fill the cache they read.
41+
# Module-level so a test can shrink it; ten real seconds per entry otherwise
42+
# dominates the end-to-end suite.
43+
_STAGGER_DELAY_SECONDS = 10.0
44+
3945

4046
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
4147
"""Set up the Lumentree integration."""
@@ -122,7 +128,7 @@ async def _prime_coordinators_staggered():
122128
except Exception as e:
123129
_LOGGER.warning("Daily coordinator first refresh failed: %s", e)
124130
# Give backfill time to populate cache, then refresh stats coordinators
125-
await asyncio.sleep(10)
131+
await asyncio.sleep(_STAGGER_DELAY_SECONDS)
126132
for coord, label in (
127133
(monthly_coord, "monthly"),
128134
(yearly_coord, "yearly"),

‎const.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def get_timezone(hass: HomeAssistant):
2828
URL_GET_BAT_DAY_DATA: Final = "/lesvr/getBatDayData"
2929
URL_GET_YEAR_DATA: Final = "/lesvr/getYearData"
3030
URL_GET_MONTH_DATA: Final = "/lesvr/getMonthData"
31+
# Single-call replacement for the three per-metric day endpoints above.
32+
# Note the absence of a "v2/" prefix: the APK contains "lesvr/v2/getAllDayData"
33+
# because app 3.2.4 targets a different host (lesvrjm.suntcn.com), but against
34+
# lesvr.suntcn.com the v2 path returns 998 (does not exist) and this one works.
35+
URL_GET_ALL_DAY_DATA: Final = "/lesvr/getAllDayData"
3136

3237
DEFAULT_HEADERS: Final = {
3338
"versionCode": "1.6.3",

0 commit comments

Comments
 (0)