feat: add support for reading and setting rfid_enabled - #695
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
secondof9
left a comment
There was a problem hiding this comment.
📋 Review Summary
Tip
Review Status: 🟢 APPROVED
Change Type: 🛠️ Refactor
Review Effort: 🟢 Low
Core Impact: Adds RFID-enabled property and command with proper version gating and type safety, following existing patterns in the library.
🚦 CI & Pipeline Health Summary
| Check / Workflow Name | Status | Impact on Review |
|---|---|---|
Analyze (actions) |
✅ PASSED | CodeQL/static analysis clean |
Analyze (python) |
✅ PASSED | Python static analysis clean |
CodeQL |
✅ PASSED | Security scan passed |
build (3.13) |
✅ PASSED | Python 3.13 build clean |
build (3.14) |
✅ PASSED | Python 3.14 build clean |
codecov/patch |
✅ PASSED | Patch coverage maintained |
coverage |
✅ PASSED | Coverage thresholds met |
linkChecker |
✅ PASSED | Markdown link check passed |
prek |
✅ PASSED | Pre-commit hooks passed |
CodeRabbit |
⏩ SKIPPED | Auto-reviews disabled (org setting) |
Note
CI Pipeline Clear: All 12 GitHub Actions workflows completed successfully.
🔍 Architectural Walkthrough
openevsehttp/commands.py
set_rfid_enabled(lines 700–720)- Follows the established async command pattern: version guard → type validation → POST → response normalization → error mapping → optimistic state update.
self._version_check("4.1.4")properly gates the feature to firmware 4.1.4+, raisingUnsupportedFeatureon older versions — matchesset_charge_modeand other similar commands.isinstance(enable, bool)validation guards against accidental int/str input (Python booleans are subclass of int, soisinstance(True, int)would be True — explicit bool check is correct here).- The endpoint, payload shape (
{"rfid_enabled": enable}), and error message format are consistent with sibling commands (set_service_level,set_mqtt_vehicle_range_miles). - State update
self._config["rfid_enabled"] = enableis optimistic (no GET round-trip) but acceptable since the firmware has just confirmed the value; consistent withdivert_mode.
openevsehttp/properties.py
rfid_enabled(lines 572–578)- Property returns
bool | Noneto signal "key absent" without raising — caller can distinguish "not supported" (raisesUnsupportedFeature) from "supported but unknown" (None). self._config.get("rfid_enabled")is the right defensive read; the parallel command's optimistic write guarantees the key is set after a successfulset_rfid_enabled, but on a freshupdate()the firmware may omit the key when the feature is configured off in another way.- No I/O in getter — purely reflects the cached
_configdict. Good. - Version guard mirrors
current_power's structure.
- Property returns
tests/test_commands.py & tests/test_properties.py
- Test coverage is comprehensive:
test_set_rfid_enabledcovers: old-firmware gate (UnsupportedFeature), True success path, False success path, TypeError on non-bool, CommandFailedError on"msg": "error".test_rfid_enabled_propertycovers: old-firmware raise, supported firmware True, supported firmware False, key absent returns None.- The
test_simple_propertiesparametrized table now includes RFID rows fortest_charger,test_charger_v2, andtest_charger_new— verifying the gate and the value across the fixture matrix. - The test does not add a
mock_aioclient.postfor the TypeError branch (correct — the TypeError fires before any HTTP call), and does add one for theCommandFailedErrorbranch (correct — the request must complete to surface a bad response). # type: ignore[arg-type]on the"invalid"str argument keeps ruff/mypy happy without weakening the test.
🔗 Related / Outside-Diff Context
(Include this section ONLY if addressing files not directly modified in the PR diff)
openevsehttp/client.py: Not modified in this PR. Consumers should still rely on the client'supdate()cycle to refresh_configso therfid_enabledproperty stays current; the new property is read-only with respect to the network.- Downstream
ha-openevseintegration (not in this repo): When this version is bumped there, expose the newrfid_enabledas aswitchentity backed byset_rfid_enabledand the cached property — the optimistic write means the switch state will reflect the user action immediately without an extra round-trip.
Description
Add support for reading and setting the
rfid_enabledconfiguration setting on OpenEVSE chargers.Both the property and the command method are version-gated to WiFi firmware version 4.1.4 or newer (when RFID support was introduced upstream), raising
UnsupportedFeatureon older versions.Fixes #694
Type of change
Checklist