Skip to content

Fix battery_rate_max validation to accept float sensor values#3642

Merged
springfall2008 merged 2 commits intospringfall2008:mainfrom
warksit:fix/battery-rate-max-validation
Mar 24, 2026
Merged

Fix battery_rate_max validation to accept float sensor values#3642
springfall2008 merged 2 commits intospringfall2008:mainfrom
warksit:fix/battery-rate-max-validation

Conversation

@warksit
Copy link
Contributor

@warksit warksit commented Mar 23, 2026

Summary

  • battery_rate_max config validation requires integer but sensors (e.g. SIG's sigen_plant_ess_rated_discharging_power) return float values like 9.6 (kW)
  • int("9.6") raises ValueError in validate_is_int(), causing a validation error on every cycle
  • Changed sensor_type from "integer" to "float" in config.py, matching the pattern used by export_limit and inverter_limit
  • Downstream code (inverter.py line 379, get_arg with required_unit="W") already handles float-to-watts conversion correctly

Test plan

  • pre-commit run --all-files passes
  • Unit tests pass (pre-existing multi_car_iog failure unrelated)
  • Verified on live SIG system: sensor returns 9.6 kW, get_arg converts to 9600 W

🤖 Generated with Claude Code

warksit and others added 2 commits March 23, 2026 23:46
battery_rate_max validation required integer but sensors like
sigen_plant_ess_rated_discharging_power return float values (e.g. 9.6 kW).
The downstream code (inverter.py get_arg with required_unit="W") already
handles float-to-watts conversion correctly.

Changed sensor_type from "integer" to "float" in config validation,
matching the pattern used by export_limit and inverter_limit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two tests fail depending on time of day, causing spurious CI failures:

1. test_ohme_time_next_occurs_tomorrow: uses datetime.now() to compute
   "1 hour ago", which wraps past midnight after 23:00. Fixed by mocking
   datetime.now() to a fixed 14:00.

2. test_multi_car_iog_load_slots_regression: uses real now_utc to build
   IOG slot times. After 21:00 UTC, now+3h crosses midnight creating
   inconsistent state. Fixed by pinning now_utc to noon. Also added
   missing args["car_charging_limit"] for 2-car setup.

Same class of bug as PR springfall2008#3512 (non-deterministic inverter test failure).
The test suite has ~30 instances of datetime.now() across 15 test files
without time mocking — consider adopting freezegun or a test helper that
provides a fixed `now` as standard practice.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@springfall2008 springfall2008 merged commit 6337357 into springfall2008:main Mar 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants