feat(sigenergy): publish onboard_status sensor#4079
Open
mgazza wants to merge 1 commit into
Open
Conversation
Tracks a per-system onboarding status string and publishes it as sensor.<prefix>_sigenergy_<slug>_onboard_status so the SaaS connect UI can show a live approval stepper: - onboard_systems records pending_approval / in_other_vpp / firmware_no_vpp / no_permission from the API result codes - run() derives active / offboarded / pending_approval for visible systems and defaults not-yet-visible expected systems to not_onboarded - publishes the sensor for every expected system_id (covers pending systems) - test: onboard_status transitions for pending-review and in-other-VPP codes Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new per-SigEnergy-system onboarding status sensor intended for an external/UI stepper, by tracking onboarding result states and publishing them as Home Assistant entities.
Changes:
- Introduces
onboard_statustracking on the SigenergyAPI instance and updates it based on onboarding result codes. - Derives and publishes
sensor.<prefix>_sigenergy_<slug>_onboard_statusfor expected systems (including ones not yet visible). - Adds a unit test covering status mapping for pending-review and in-other-VPP result codes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| apps/predbat/sigenergy.py | Adds onboard status tracking and publishes the new onboarding-status sensor in the main run loop. |
| apps/predbat/tests/test_sigenergy.py | Adds a unit test validating onboard status mapping for specific API result codes. |
Comment on lines
+1671
to
+1674
| api._request = AsyncMock(return_value=None) | ||
| api._last_api_code = SIGENERGY_CODE_SYSTEM_PENDING_REVIEW | ||
| result = asyncio.run(api.onboard_systems(["sys-1"])) | ||
| assert result is None, "pending review returns None" |
Comment on lines
+1678
to
+1683
| api2 = MockSigenergyAPI() | ||
| api2._request = AsyncMock(return_value=None) | ||
| api2._last_api_code = SIGENERGY_CODE_IN_OTHER_VPP | ||
| result2 = asyncio.run(api2.onboard_systems("sys-2")) | ||
| assert result2 is False, "in-other-vpp returns False" | ||
| assert api2.onboard_status["sys-2"] == "in_other_vpp", "in_other_vpp status set" |
Comment on lines
837
to
841
| if code == SIGENERGY_CODE_SOFTWARE_NO_VPP: | ||
| for sid in system_ids: | ||
| self.onboard_status[str(sid)] = "firmware_no_vpp" | ||
| self.log("Warn: SigenergyAPI: Onboard failed — system {} firmware does not support VPP (code=1105)".format(system_ids)) | ||
| return False |
Comment on lines
2103
to
2107
| for sid in missing_ids: | ||
| self.onboard_status.setdefault(str(sid), "not_onboarded") | ||
| slug = self._system_slug(sid) | ||
| is_offboard_at_start = self.get_state_wrapper("switch.{}_sigenergy_{}_offboard".format(self.prefix, slug), default="off") == "on" | ||
| if is_offboard_at_start: |
Comment on lines
+2152
to
+2156
| # Derive the user-facing onboarding status for the visible system. | ||
| if is_offboard: | ||
| self.onboard_status[str(sid)] = "offboarded" | ||
| elif self.current_mode.get(sid) == SIGENERGY_MODE_VPP: | ||
| self.onboard_status[str(sid)] = "active" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Publishes a per-system
sensor.<prefix>_sigenergy_<slug>_onboard_statusso a managing UI can show a live VPP-onboarding/approval stepper.Changes
onboard_systemsrecordspending_approval/in_other_vpp/firmware_no_vpp/no_permissionfrom the API result codes.run()derivesactive/offboarded/pending_approvalfor visible systems and defaults not-yet-visible expected systems tonot_onboarded.system_id(so a pending system still gets a sensor).Read-only addition; no change to existing SigEnergy control behaviour.
🤖 Generated with Claude Code