Skip to content

Fit the Green Power endpoint into two-slot firmware - #281

Merged
puddly merged 2 commits into
devfrom
zigpy-bot/gp-endpoint-slots
Oct 28, 2026
Merged

puddly merged 2 commits into
devfrom
zigpy-bot/gp-endpoint-slots

Conversation

@zigpy-review-bot

@zigpy-review-bot zigpy-review-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes ZHA failing to start on ConBee II / RaspBee II with zigpy 2.4.x: No available endpoint slots exist (home-assistant/core#189366).

Closes #280

zigpy 2.4.0 registers the Green Power endpoint 242 next to the HA endpoint 1 and the ZLL endpoint 2, but the ConBee II / RaspBee II firmware only has two endpoint slots. add_endpoint handled one endpoint at a time:

  • When both slots already held zigpy's endpoints 1 and 2 (any stick last run with zigpy 2.1–2.3), both were treated as used and 242 raised ValueError, so startup failed on every attempt.
  • Otherwise, a slot it had just written was never marked as used, so a later endpoint could overwrite it: 242 overwrote endpoint 2 and slot 1 was rewritten twice (2, then 242) on every start, and with two slots held by another application, every endpoint went into slot 1 and endpoint 1 was never registered at all.

Changes

  • register_endpoints now collects all of zigpy's endpoints first, then fits them into the slots in one pass.
  • An endpoint with the same ID as an earlier one replaces it, so a configured endpoint can override one of zigpy's, as a standalone add_endpoint call already could.
  • If they don't fit, the ZLL endpoint 2 is dropped (a configured ZLL endpoint with another ID is kept). That's the layout deCONZ and Z2M use on these sticks (slot 0 = endpoint 1, slot 1 = endpoint 242), and zigpy-deconz never sends from endpoint 2 anyway: send_packet sends everything except ZDO (endpoint 0) and Green Power (242) from endpoint 1. If it still doesn't fit (extra endpoints configured on a two-slot stick), it raises as before.
  • Endpoints already in a slot stay where they are; only missing ones are written, preferring a slot with the same endpoint ID. A configured stick is no longer written on every start, and an upgraded one is written once (slot 1: 2 → 242).
  • A standalone add_endpoint call goes through the same path with the endpoints registered so far, so it can't overwrite one of them.

Firmware with more slots (a four-slot ConBee II test build exists) keeps endpoint 2 and puts 242 in a slot not holding one of zigpy's endpoints.

Trade-off on two-slot firmware

puddly's hardware test on a ConBee II (0x26780700) shows that the firmware only delivers incoming frames whose destination endpoint is in a slot with a matching profile, and doesn't ACK the others. With two slots, one of zigpy's three endpoints is always missing:

  • without 242, Green Power frames forwarded by proxies are dropped (frames received directly still arrive through the firmware's GP indication);
  • without endpoint 2, ZLL-profile (0xC05E) frames sent to the coordinator are dropped.

This PR gives up the ZLL endpoint, the same choice deCONZ and Z2M make. Sending is unaffected either way, since the firmware doesn't check source endpoints.

Testing

  • New tests run zigpy's real register_endpoints against mocked slot tables: two slots upgraded from zigpy ≤ 2.3 (ValueError before), two slots already holding 1 + 242 (two writes per start before, none now), two slots from another application, and three/four slots. Each also checks that registering again writes nothing.
  • Too many endpoints still raise without writing anything, also when the only other ZLL endpoint is a configured one; a configured endpoint with zigpy's endpoint ID replaces it; a later add_endpoint uses a free slot or the slot with the same endpoint ID.
  • 154 passed with zigpy 2.4.1. The four slot-layout cases and the override case fail against dev.
  • Not tested on hardware yet. A test on a ConBee II that ran ZHA before 2026.11 would confirm it; ConBee II / RaspBee II fail to start since zigpy 2.4.0: no endpoint slot left for the Green Power endpoint 242 #280 has instructions and a test build for Home Assistant OS.

zigpy 2.4.0 registers the Green Power endpoint 242 next to the HA (1) and
ZLL (2) endpoints, but ConBee II and RaspBee II firmware only has two
endpoint slots. When both slots already held zigpy's endpoints 1 and 2,
`add_endpoint` raised `No available endpoint slots exist` and startup
failed on every attempt. Otherwise, a written slot was never marked as
used, so endpoint 242 overwrote endpoint 2 and slot 1 was rewritten twice
on every start.

Register all endpoints at once instead: when they don't fit, drop the ZLL
endpoint (nothing is sent from it), the same layout deCONZ and Z2M use,
keep endpoints that are already configured and only write the rest.
A configured endpoint with the ID of one of zigpy's replaces it, as a
standalone `add_endpoint` call already did, instead of taking a slot of
its own. Only zigpy's ZLL endpoint 2 makes room on two-slot firmware, a
configured ZLL endpoint is kept.
@zigpy-review-bot zigpy-review-bot added the bugfix This PR fixes a bug label Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (1bb30c8) to head (7d9b369).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #281      +/-   ##
==========================================
+ Coverage   99.15%   99.17%   +0.02%     
==========================================
  Files           7        7              
  Lines         945      971      +26     
==========================================
+ Hits          937      963      +26     
  Misses          8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES
TheJulianJES requested a balanced review from Copilot October 28, 2026 23:13
@TheJulianJES
TheJulianJES marked this pull request as ready for review October 28, 2026 23:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Maintainer acceptance of the loss of incoming ZLL reception and hardware validation of two-slot startup and Green Power proxy reception are still needed, as slot-table mocks cannot verify firmware behavior.

No open issues 🎉

What changed in this PR

Fixes endpoint registration for ConBee II / RaspBee II firmware with only two slots, addressing the ZHA startup failure introduced by zigpy’s Green Power endpoint registration.

Changes:

  • Collects endpoints before assigning slots, omitting ZLL endpoint 2 when needed to fit HA and Green Power.
  • Preserves matching descriptors, supports same-ID overrides, and tracks registered endpoints to prevent unintended overwrites.
  • Adds regression tests for slot layouts, repeat registration, capacity errors, overrides, and later endpoint additions.
File Description
zigpy_deconz/​zigbee/​application.py Batches endpoint registration and allocates available firmware slots while avoiding unnecessary writes.
tests/​test_application.py Tests slot allocation, registration stability, capacity handling, and endpoint replacement.

Review effort: Balanced

@puddly
puddly merged commit 0a6de21 into dev Oct 28, 2026
23 checks passed
@TheJulianJES

Copy link
Copy Markdown
Contributor

(note: do not press "Delete branch" yet, as the custom component installs this branch currently)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConBee II / RaspBee II fail to start since zigpy 2.4.0: no endpoint slot left for the Green Power endpoint 242

4 participants