Skip to content

Fix target_soc passed as float in service API calls#4215

Merged
springfall2008 merged 3 commits into
mainfrom
copilot/fix-target-soc-type
Jul 9, 2026
Merged

Fix target_soc passed as float in service API calls#4215
springfall2008 merged 3 commits into
mainfrom
copilot/fix-target-soc-type

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

When Predbat calls charge_start_service or discharge_start_service, target_soc was passed as a float. Home Assistant's WebSocket API requires it to be an integer, causing:

Warn: Web Socket result failed {'id': 65, 'type': 'result', 'success': False,
  'error': {'code': 'invalid_format', 'message': "expected int for dictionary value @ data['target_soc']"}}

Changes

  • inverter.pyadjust_charge_immediate: cast target_soc to int in the service data dict
  • inverter.pyadjust_export_immediate: same fix for the discharge path

power was already wrapped in int(); target_soc now follows the same pattern.

Copilot AI changed the title [WIP] Fix target_soc type from float to int Fix target_soc passed as float in service API calls Jul 8, 2026
Copilot AI requested a review from springfall2008 July 8, 2026 21:54
@springfall2008 springfall2008 marked this pull request as ready for review July 8, 2026 23:06
Copilot AI review requested due to automatic review settings July 8, 2026 23:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Home Assistant WebSocket service-call validation failures by ensuring target_soc is sent as an integer (HA rejects floats for target_soc in service data). The change is localized to the “immediate” charge/discharge service-call payload construction in the inverter control layer.

Changes:

  • Cast target_soc to int(...) in adjust_charge_immediate() service payload.
  • Cast target_soc to int(...) in adjust_export_immediate() service payload.

Comment thread apps/predbat/inverter.py
Comment on lines 2758 to 2763
current_rate = self.get_current_charge_rate()
service_data = {
"device_id": self.base.get_arg("device_id", index=self.id, default=""),
"target_soc": target_soc,
"target_soc": int(target_soc),
"power": int(current_rate),
}
Comment thread apps/predbat/inverter.py
Comment on lines 2786 to 2791
if target_soc < 100:
service_data = {
"device_id": self.base.get_arg("device_id", index=self.id, default=""),
"target_soc": target_soc,
"target_soc": int(target_soc),
"power": int(self.battery_rate_max_discharge * MINUTE_WATT),
}
@springfall2008 springfall2008 merged commit b73db64 into main Jul 9, 2026
2 checks passed
@springfall2008 springfall2008 deleted the copilot/fix-target-soc-type branch July 9, 2026 17:53
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.

Service API target_soc is float instead of int

3 participants