Fix TypeError when time entities used for discharge/charge hour config with GS_fb00#3826
Conversation
…rge_end_hour with GS_fb00 Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/a836cefc-6427-4317-bd5d-9925b5d073c4 Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
…heck Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/a836cefc-6427-4317-bd5d-9925b5d073c4 Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
|
This fix solves my exact problem. |
There was a problem hiding this comment.
Pull request overview
Fixes crashes and incorrect writes when Solis GS_fb00 exposes TOU slot controls as time.* entities (instead of separate hour/minute number.* entities), ensuring PredBat can safely write charge/discharge windows using either representation.
Changes:
- Harden
write_and_poll_optionby coercingnew_valuetostrbefore string operations, preventingTypeErrorwhen integers are passed. - Update
adjust_force_exportto detecttime.*entities for discharge slot hour/minute configs and write the full"HH:MM:SS"string instead of integer components. - Apply the same
time.*detection/full-time write behavior inadjust_charge_windowfor charge slot hour/minute configs.
| # If the entity is a time entity (e.g. for FB00 firmware), write the full time string instead of just the integer component | ||
| start_hour_id = self.base.get_arg("charge_start_hour", indirect=False, index=self.id) | ||
| if start_hour_id and isinstance(start_hour_id, str) and start_hour_id.startswith("time."): | ||
| self.write_and_poll_option("charge_start_hour", start_hour_id, new_start) | ||
| else: | ||
| self.write_and_poll_option("charge_start_hour", start_hour_id, int(new_start[:2])) | ||
| start_minute_id = self.base.get_arg("charge_start_minute", indirect=False, index=self.id) | ||
| if start_minute_id and isinstance(start_minute_id, str) and start_minute_id.startswith("time."): | ||
| self.write_and_poll_option("charge_start_minute", start_minute_id, new_start) | ||
| else: | ||
| self.write_and_poll_option("charge_start_minute", start_minute_id, int(new_start[3:5])) |
There was a problem hiding this comment.
The new behavior for GS_fb00/time.* entities (writing full "HH:MM:SS" to _hour/_minute when those config args resolve to time.) isn’t covered by existing inverter tests. Please add a unit test case (e.g., in apps/predbat/tests/test_inverter.py) that sets discharge/charge *_hour (and optionally _minute) to a time. entity and verifies adjust_force_export/adjust_charge_window call the time service with the full time string and don’t attempt to write integer components.
|
@copilot add unit test for this change |
…rt and adjust_charge_window Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/e47fd91a-a100-445a-9cc2-a846d6d2a8d1 Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Done in commit f325a2d. Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Looking forward for the update, this is the fix I need and waiting for. Thank you 😊👍 |
Solis GS_fb00 (FB00 firmware) exposes
time.*entities for TOU slots rather than separatenumber.*hour/minute entities. Whendischarge_start_hour/discharge_end_hour(and charge equivalents) are mapped to thesetimeentities, PredBat crashes inwrite_and_poll_optionbecause integer hour values (e.g.22) are passed to":" in new_value.Changes
write_and_poll_option— defensive fix: Convertnew_valuetostrbefore the":" in new_valuecheck, preventingTypeError: argument of type 'int' is not iterablefor any integer passed to atime/selectentity.adjust_force_export— correct fix: Wheninv_charge_time_format == "H M", detect ifdischarge_start_hour,discharge_start_minute,discharge_end_hour, ordischarge_end_minuteresolves to atime.*entity. If so, write the full time string ("HH:MM:SS") instead of the extracted integer component — which would otherwise produce an invalid value and overwrite the minutes to:00.adjust_charge_window— same fix: Applied the same detection and full-time-string write forcharge_start_hour,charge_start_minute,charge_end_hour, andcharge_end_minute.TestHAInterface— mock extended: Addedtime/set_valueservice handling so the test mock correctly updates entity state when atime.*entity is written.Unit tests added:
test_time_entity_hour_writeintests/test_inverter.pycovers bothadjust_force_exportandadjust_charge_windowwithtime.*entities, verifying the full"HH:MM:SS"string is written and noTypeErroris raised.Entity domain detection uses
startswith("time.")rather than.split(".")[0]to avoid a potentialIndexError.