Skip to content

feat(sensors): add home_battery() to push home/powerwall battery data#617

Merged
firstof9 merged 1 commit into
firstof9:mainfrom
RAR:feature/home-battery-push-v1
Jun 14, 2026
Merged

feat(sensors): add home_battery() to push home/powerwall battery data#617
firstof9 merged 1 commit into
firstof9:mainfrom
RAR:feature/home-battery-push-v1

Conversation

@RAR

@RAR RAR commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a home_battery() push helper to SensorsMixin, mirroring the existing soc() / set_shaper_live_pwr() pattern. It POSTs home_battery_soc and/or home_battery_power to {url}status so a Home Assistant integration (or any caller) can push home/powerwall battery state to the charger.

Details

  • home_battery(soc=None, power=None) — sends only the fields provided; logs and no-ops when called with neither.
  • Version-gated at firmware 4.1.0 (raises UnsupportedFeature below that), same gate as soc().
  • New const keys HOME_BATTERY_SOC / HOME_BATTERY_POWER matching the firmware's /status POST keys.

Testing

  • New test_home_battery covers: both fields, single field, no-data, and the unsupported-firmware path.
  • Full suite green locally: 421 passed.

Context

Pairs with a Home Assistant firstof9/openevse integration PR that wires user-mapped HA battery sensors to this method (linked there). The firmware side already parses home_battery_soc/home_battery_power on POST /status.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added home battery and powerwall sensor integration: chargers can now receive battery state of charge and power data for optimized charging. Includes flexible parameter support (state of charge, power, or both) with automatic firmware version compatibility checks.

Mirror of the existing soc() push helper: POST home_battery_soc and/or
home_battery_power to {url}status, version-gated at firmware 4.1.0. Adds
the two const keys plus a unit test covering both-fields, single-field,
no-data, and the unsupported-firmware (UnsupportedFeature) paths.
@github-actions github-actions Bot added the feature New Features label Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9814d209-d568-49e1-87b1-72367f531f08

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@secondof9

Copy link
Copy Markdown

Code Review: PR #617 — Add Home Battery Sensors

🔴 Critical

⚠️ Warnings

💡 Suggestions

  • Consider adding a guard against empty payloads before the POST request to avoid sending empty JSON bodies to the device.

✅ Looks Good

The implementation correctly mirrors the existing soc() pattern and properly handles feature version gating. The logging is consistent and debug-level as expected. The test coverage is solid, including edge cases for empty parameters and older firmware versions.

@firstof9

Copy link
Copy Markdown
Owner

Thanks @RAR, please review the suggestion.

@RAR

RAR commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The empty-payload guard you suggested is already in place — home_battery() only POSTs inside the else branch:

if not data:
    _LOGGER.info("No home battery data to send to device.")
else:
    _LOGGER.debug("Posting home battery data: %s", data)
    response = await self.process_request(url=url, method="post", data=data)
    ...

Called with neither soc nor power, it logs and no-ops rather than sending an empty body (covered by the no-data case in test_home_battery). This mirrors the existing soc() / grid_voltage() / self_production() push helpers, which all use the same if not data: guard. So no change needed here.

@firstof9 firstof9 merged commit 45a97ba into firstof9:main Jun 14, 2026
12 checks passed
RAR pushed a commit to RAR/openevse-ha that referenced this pull request Jun 14, 2026
1.3.0 adds home_battery() (firstof9/python-openevse-http#617); the vehicle
SoC/range/ETA push already worked via soc() in 1.2.0. Also corrects the
manifest pin, which was stale at 1.0.1 while requirements.txt was at 1.2.0.
Addresses the 'please include a library version bump' review on firstof9#646.
firstof9 pushed a commit to firstof9/openevse that referenced this pull request Jun 15, 2026
…e charger (#646)

* feat: push vehicle SoC/range/ETA and home battery to the charger

Wire user-mapped Home Assistant sensors to the charger's POST /status
push API via python-openevse-http:
- vehicle_soc / vehicle_range / vehicle_eta -> manager.soc(...)
- home_battery_soc / home_battery_power     -> manager.home_battery(...)

Adds the five CONF_* keys + SENSOR_FIELDS entries, options-flow entity
selectors, state-change listener blocks, en/es translations, and tests
(config-flow expected dicts + push round-trip in test_init).

* build: bump python-openevse-http to 1.3.0 (home_battery push support)

1.3.0 adds home_battery() (firstof9/python-openevse-http#617); the vehicle
SoC/range/ETA push already worked via soc() in 1.2.0. Also corrects the
manifest pin, which was stale at 1.0.1 while requirements.txt was at 1.2.0.
Addresses the 'please include a library version bump' review on #646.

* test: cover vehicle/home-battery push branches for 100% patch coverage

Add coverage for the unavailable/unknown/empty -> None path, the
non-numeric warning path on range/ETA/power, and both the
UnsupportedFeature and connection-error handlers on each push block
in handle_state_change. Brings patch coverage to 100% (full suite
107 passed, custom_components/openevse at 100%).

---------

Co-authored-by: Andrew Rankin <andrewrankin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants