Sitelet https://github.com/zigpy/zigpy/pull/1256
Skip to content

Use first existing endpoint for basic cluster instead of hardcoded number - #1256

Closed
Shulyaka wants to merge 2 commits into
zigpy:devfrom
Shulyaka:patch-1
Closed

Shulyaka wants to merge 2 commits into
zigpy:devfrom
Shulyaka:patch-1

Conversation

@Shulyaka

@Shulyaka Shulyaka commented Sep 8, 2023

Copy link
Copy Markdown
Contributor

On #1238 we add Basic cluster to endpoint 1.
This PR makes sure that that endpoint actually exists.

Mostly applicable to xbee coordinators: https://github.com/zigpy/zigpy-xbee/blob/dev/zigpy_xbee/zigbee/application.py#L381

@puddly

puddly commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

Thanks! Does the xbee have an API to register new endpoints? Zigpy radio libraries should implement the register_endpoint method, which would have set up endpoint 1 on startup.

Comment thread zigpy/application.py Outdated
Comment on lines 1224 to 1229
if 1 not in self._device.endpoints:
self._device.add_endpoint(1)

cluster = self._device.endpoints[1].add_input_cluster(
zigpy.zcl.clusters.general.Basic.cluster_id
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it does not, however I believe new endpoints can be implemented on the application level.

If you feel uncomfortable adding an endpoint, we could instead pick the first existing one like this:

Suggested change
if 1 not in self._device.endpoints:
self._device.add_endpoint(1)
cluster = self._device.endpoints[1].add_input_cluster(
zigpy.zcl.clusters.general.Basic.cluster_id
)
cluster = self._device.non_zdo_endpoints[0].add_input_cluster(
zigpy.zcl.clusters.general.Basic.cluster_id
)

Please advise.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perhaps it would be best for the XBee implementation to call await self.register_endpoints() within start_network and then to implement register_endpoint to just call add_endpoint. This is more of a radio library bug more than a zigpy bug, in my opinion.

@Shulyaka Shulyaka Sep 8, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is endpoint 1 mandatory or is zigpy just making an assumption?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes. Zigpy registers endpoints explicitly on startup:

async def register_endpoints(self) -> None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I will check.

@Shulyaka

Shulyaka commented Sep 8, 2023 •

Copy link
Copy Markdown
Contributor Author

Updated. It looks like a more clean solution

@Shulyaka Shulyaka changed the title Make sure endpoint 1 exists Use first existing endpoint for basic cluster instead of hardcoded number Sep 8, 2023
@Shulyaka
Shulyaka marked this pull request as draft September 8, 2023 22:12
@Shulyaka

Shulyaka commented Sep 9, 2023 •

Copy link
Copy Markdown
Contributor Author

Closed in favor of zigpy/zigpy-xbee#145 and zigpy/zigpy-zigate#146.

UPD: Do we also need a similar fix for zigpy_deconz?

@Shulyaka Shulyaka closed this Sep 9, 2023
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.

2 participants