-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read out the supported and unsupported attribute of a device at configure #101
Draft
elupus
wants to merge
10
commits into
zigpy:dev
Choose a base branch
from
elupus:unsupported
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−14
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4962ff5
Update unsupported attribute on configure
elupus 48c5111
Rename to unsupported in log
elupus 1110a5a
Mock discover attributes to list all
elupus 744a031
Attempt to fix tests
elupus b1aba9a
Patch each instance of cluster
elupus 474925c
Only discover attributes on initialize
elupus 0fbbad4
Drop uneeded patch import
elupus f97d8b3
Support marking attributes as unsupported in tests
elupus 882e038
Merge remote-tracking branch 'origin/dev' into unsupported
elupus c16d356
Only grab unsupported when we are not using cache
elupus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,15 @@ | |
from typing import TYPE_CHECKING, Any, Final, ParamSpec, TypedDict | ||
|
||
import zigpy.exceptions | ||
import zigpy.types | ||
import zigpy.util | ||
import zigpy.zcl | ||
from zigpy.zcl.foundation import ( | ||
GENERAL_COMMANDS, | ||
CommandSchema, | ||
ConfigureReportingResponseRecord, | ||
DiscoverAttributesResponseRecord, | ||
GeneralCommand, | ||
Status, | ||
ZCLAttributeDef, | ||
) | ||
|
@@ -441,6 +445,7 @@ async def async_configure(self) -> None: | |
if ch_specific_cfg: | ||
self.debug("Performing cluster handler specific configuration") | ||
await ch_specific_cfg() | ||
|
||
self.debug("finished cluster handler configuration") | ||
else: | ||
self.debug("skipping cluster handler configuration") | ||
|
@@ -458,6 +463,10 @@ async def async_initialize(self, from_cache: bool) -> None: | |
uncached = [a for a, cached in self.ZCL_INIT_ATTRS.items() if not cached] | ||
uncached.extend([cfg["attr"] for cfg in self.REPORT_CONFIG]) | ||
|
||
if not from_cache: | ||
self.debug("discovering unsupported attributes") | ||
await self.discover_unsupported_attributes() | ||
|
||
if cached: | ||
self.debug("initializing cached cluster handler attributes: %s", cached) | ||
await self._get_attributes( | ||
|
@@ -624,6 +633,47 @@ async def write_attributes_safe( | |
f"Failed to write attribute {name}={value}: {record.status}", | ||
) | ||
|
||
async def _discover_attributes_all( | ||
self, | ||
) -> list[DiscoverAttributesResponseRecord] | None: | ||
discovery_complete = zigpy.types.Bool.false | ||
start_attribute_id = 0 | ||
attribute_info = [] | ||
cluster = self.cluster | ||
while discovery_complete != zigpy.types.Bool.true: | ||
rsp = await cluster.discover_attributes( | ||
start_attribute_id=start_attribute_id, max_attribute_ids=0xFF | ||
) | ||
if not isinstance( | ||
rsp, GENERAL_COMMANDS[GeneralCommand.Discover_Attributes_rsp].schema | ||
): | ||
self.debug( | ||
"Ignoring attribute discovery due to unexpected default response: %r", | ||
rsp, | ||
) | ||
return None | ||
|
||
attribute_info.extend(rsp.attribute_info) | ||
discovery_complete = rsp.discovery_complete | ||
start_attribute_id = ( | ||
max((info.attrid for info in rsp.attribute_info), default=0) + 1 | ||
) | ||
return attribute_info | ||
|
||
async def discover_unsupported_attributes(self): | ||
"""Discover the list of unsupported attributes from the device.""" | ||
attribute_info = await self._discover_attributes_all() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also i'm not fully sure what type of errors devices might respond with here. We may want to gracefully handle some things. For example, the GeneralCommand.Default_Response response is sent by some quirks here which seem utterly wrong. |
||
if attribute_info is None: | ||
return | ||
attr_ids = {info.attrid for info in attribute_info} | ||
|
||
cluster = self.cluster | ||
for attr_id in cluster.attributes: | ||
if attr_id in attr_ids: | ||
cluster.remove_unsupported_attribute(attr_id) | ||
else: | ||
cluster.add_unsupported_attribute(attr_id) | ||
|
||
def log(self, level, msg, *args, **kwargs) -> None: | ||
"""Log a message.""" | ||
msg = f"[%s:%s]: {msg}" | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wan't sure if this should go here in ZHA or in ZIGPY. The cache of unsupported attributes does exist in ZIGPY.