Skip to content
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

Small speed up to fetch characteristic values #363

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Conversation

bdraco
Copy link
Collaborator

@bdraco bdraco commented Feb 22, 2024

We can avoid most of the body of this function for the common case. We call this a lot when adding entities

Screenshot 2024-02-22 at 2 15 09 AM

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5d8c8f1) 74.47% compared to head (74b0822) 74.51%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
+ Coverage   74.47%   74.51%   +0.04%     
==========================================
  Files          99       99              
  Lines        9331     9332       +1     
==========================================
+ Hits         6949     6954       +5     
+ Misses       2382     2378       -4     

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

@Jc2k
Copy link
Owner

Jc2k commented Feb 22, 2024

Tangentially related, but do you think there is a nicer way to replace this entirely so we can do more strict type checking in HA? Was thinking about read_int(), read_string(), etc. I guess they could return self._value pretty directly and avoid the body too. But not sure about returning enums of different types and different TLV structs with that approach. Can sort of imagine a read_struct that took a class, and the return value was generic over that parameter.

If we did that is there a performant way (or, do we disable asserts at runtime in HA?) to check self.format matches the read function getting called?

@bdraco
Copy link
Collaborator Author

bdraco commented Feb 22, 2024

I think we could subclass char objects for each HAP type with the value param typed to the expected return. Than each CharacteristicTLV8, etc could implement its own value function or use the default.

@bdraco bdraco marked this pull request as ready for review February 22, 2024 17:11
@bdraco bdraco merged commit 59a0078 into main Feb 27, 2024
12 checks passed
@bdraco bdraco deleted the value_char_perf branch February 27, 2024 17:22
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