Skip to content

Fix TypeError when time entities used for discharge/charge hour config with GS_fb00#3826

Merged
springfall2008 merged 4 commits intomainfrom
copilot/fix-typeerror-discharge-hours
Apr 25, 2026
Merged

Fix TypeError when time entities used for discharge/charge hour config with GS_fb00#3826
springfall2008 merged 4 commits intomainfrom
copilot/fix-typeerror-discharge-hours

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

Solis GS_fb00 (FB00 firmware) exposes time.* entities for TOU slots rather than separate number.* hour/minute entities. When discharge_start_hour/discharge_end_hour (and charge equivalents) are mapped to these time entities, PredBat crashes in write_and_poll_option because integer hour values (e.g. 22) are passed to ":" in new_value.

Changes

  • write_and_poll_option — defensive fix: Convert new_value to str before the ":" in new_value check, preventing TypeError: argument of type 'int' is not iterable for any integer passed to a time/select entity.

  • adjust_force_export — correct fix: When inv_charge_time_format == "H M", detect if discharge_start_hour, discharge_start_minute, discharge_end_hour, or discharge_end_minute resolves to a time.* 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 for charge_start_hour, charge_start_minute, charge_end_hour, and charge_end_minute.

  • TestHAInterface — mock extended: Added time/set_value service handling so the test mock correctly updates entity state when a time.* entity is written.

  • Unit tests added: test_time_entity_hour_write in tests/test_inverter.py covers both adjust_force_export and adjust_charge_window with time.* entities, verifying the full "HH:MM:SS" string is written and no TypeError is raised.

Entity domain detection uses startswith("time.") rather than .split(".")[0] to avoid a potential IndexError.

# apps.yaml — FB00 firmware setup that previously crashed on discharge
discharge_start_hour:
  - time.solis_rhi_3p_grid_time_of_use_discharge_start_slot_1
discharge_end_hour:
  - time.solis_rhi_3p_grid_time_of_use_discharge_end_slot_1

Copilot AI and others added 2 commits April 24, 2026 08:04
…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>
Copilot AI changed the title [WIP] Fix TypeError when using time entities for discharge hours Fix TypeError when time entities used for discharge/charge hour config with GS_fb00 Apr 24, 2026
Copilot AI requested a review from springfall2008 April 24, 2026 08:08
@Gammaed
Copy link
Copy Markdown

Gammaed commented Apr 24, 2026

This fix solves my exact problem.
Tested on Solis RHI-3P10K-HVES-5G firmware 1A0040-60000D
with GS_fb00 inverter type and time entities.
Please merge this fix!

@springfall2008 springfall2008 marked this pull request as ready for review April 24, 2026 10:52
Copilot AI review requested due to automatic review settings April 24, 2026 10:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_option by coercing new_value to str before string operations, preventing TypeError when integers are passed.
  • Update adjust_force_export to detect time.* 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 in adjust_charge_window for charge slot hour/minute configs.

Comment thread apps/predbat/inverter.py
Comment on lines +2612 to +2622
# 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]))
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 generated this review using guidance from repository custom instructions.
@springfall2008
Copy link
Copy Markdown
Owner

@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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 24, 2026

@copilot add unit test for this change

Done in commit f325a2d. Added test_time_entity_hour_write in test_inverter.py with 4 test cases (discharge and charge, two time values each). The tests verify that adjust_force_export and adjust_charge_window write the full "HH:MM:SS" string to time.* entities rather than integer hour components, and confirm no TypeError is raised. Also added time/set_value handling to TestHAInterface in test_infra.py so the mock correctly updates dummy_items when a time entity is written.

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:

  • gitlab.com
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED (dns block)
  • https://api.github.com/repos/springfall2008/batpred/contents/apps/predbat
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick --test inverter (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Gammaed
Copy link
Copy Markdown

Gammaed commented Apr 24, 2026

Looking forward for the update, this is the fix I need and waiting for. Thank you 😊👍

@springfall2008 springfall2008 merged commit 58159d7 into main Apr 25, 2026
1 check passed
@springfall2008 springfall2008 deleted the copilot/fix-typeerror-discharge-hours branch April 25, 2026 10:32
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.

TypeError: argument of type 'int' is not iterable with GS_fb00 + time entities for discharge_start_hour/discharge_end_hour

4 participants