-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Style change follow up #13707
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
Merged
Merged
Style change follow up #13707
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
03eb379
Style improvements
cdce8p 5243038
Rewritten get_accessory
cdce8p 8703cb2
Added log statement
cdce8p 2b05f1e
Return None
cdce8p cb0aad4
Pass config instead of **a_kwargs
cdce8p dfa7191
Thermostat: Moved feature check to type file
cdce8p 99b67df
Init_setup
cdce8p 2f7ce59
Small changes
cdce8p 2793753
Use super().__init__(*args, category=CATEGORY)
cdce8p d99f9df
Fix light set_color_temperature call
cdce8p 0af42de
Added setup_char helper function
cdce8p e0eabb1
Improved type_thermostat optional chars
cdce8p 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,14 @@ | |
| from pyhap.accessory import Accessory, Bridge, Category | ||
| from pyhap.accessory_driver import AccessoryDriver | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.core import callback as ha_callback | ||
| from homeassistant.helpers.event import ( | ||
| async_track_state_change, track_point_in_utc_time) | ||
| from homeassistant.util import dt as dt_util | ||
|
|
||
| from .const import ( | ||
| DEBOUNCE_TIMEOUT, ACCESSORY_MODEL, ACCESSORY_NAME, BRIDGE_MODEL, | ||
| BRIDGE_NAME, MANUFACTURER, SERV_ACCESSORY_INFO, CHAR_MANUFACTURER, | ||
| DEBOUNCE_TIMEOUT, BRIDGE_MODEL, BRIDGE_NAME, MANUFACTURER, | ||
| SERV_ACCESSORY_INFO, CHAR_MANUFACTURER, | ||
| CHAR_MODEL, CHAR_NAME, CHAR_SERIAL_NUMBER) | ||
| from .util import ( | ||
| show_setup_message, dismiss_setup_message) | ||
|
|
@@ -24,7 +24,7 @@ | |
|
|
||
| def debounce(func): | ||
| """Decorator function. Debounce callbacks form HomeKit.""" | ||
| @callback | ||
| @ha_callback | ||
| def call_later_listener(*args): | ||
| """Callback listener called from call_later.""" | ||
| # pylint: disable=unsubscriptable-object | ||
|
|
@@ -72,6 +72,18 @@ def add_preload_service(acc, service, chars=None): | |
| return service | ||
|
|
||
|
|
||
| def setup_char(char_name, service, value=None, properties=None, callback=None): | ||
| """Helper function to return fully configured characteristic.""" | ||
| char = service.get_characteristic(char_name) | ||
| if value: | ||
| char.value = value | ||
| if properties: | ||
| char.override_properties(properties) | ||
| if callback: | ||
| char.setter_callback = callback | ||
| return char | ||
|
|
||
|
|
||
| def set_accessory_info(acc, name, model, manufacturer=MANUFACTURER, | ||
| serial_number='0000'): | ||
| """Set the default accessory information.""" | ||
|
|
@@ -85,34 +97,47 @@ def set_accessory_info(acc, name, model, manufacturer=MANUFACTURER, | |
| class HomeAccessory(Accessory): | ||
| """Adapter class for Accessory.""" | ||
|
|
||
| # pylint: disable=no-member | ||
|
|
||
| def __init__(self, name=ACCESSORY_NAME, model=ACCESSORY_MODEL, | ||
| category='OTHER', **kwargs): | ||
| def __init__(self, hass, name, entity_id, aid, category): | ||
| """Initialize a Accessory object.""" | ||
| super().__init__(name, **kwargs) | ||
| set_accessory_info(self, name, model) | ||
| super().__init__(name, aid=aid) | ||
| set_accessory_info(self, name, model=entity_id) | ||
| self.category = getattr(Category, category, Category.OTHER) | ||
| self.entity_id = entity_id | ||
| self.hass = hass | ||
|
|
||
| def _set_services(self): | ||
| add_preload_service(self, SERV_ACCESSORY_INFO) | ||
|
|
||
| def run(self): | ||
| """Method called by accessory after driver is started.""" | ||
| state = self.hass.states.get(self.entity_id) | ||
| self.update_state(new_state=state) | ||
| self.update_state_callback(new_state=state) | ||
| async_track_state_change( | ||
| self.hass, self.entity_id, self.update_state) | ||
| self.hass, self.entity_id, self.update_state_callback) | ||
|
|
||
| def update_state_callback(self, entity_id=None, old_state=None, | ||
| new_state=None): | ||
| """Callback from state change listener.""" | ||
| _LOGGER.debug('New_state: %s', new_state) | ||
| if new_state is None: | ||
| return | ||
| self.update_state(new_state) | ||
|
|
||
| def update_state(self, new_state): | ||
|
Member
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. 👍 This is a good idea and seem to simplify things as well |
||
| """Method called on state change to update HomeKit value. | ||
|
|
||
| Overridden by accessory types. | ||
| """ | ||
| pass | ||
|
|
||
|
|
||
| class HomeBridge(Bridge): | ||
| """Adapter class for Bridge.""" | ||
|
|
||
| def __init__(self, hass, name=BRIDGE_NAME, | ||
| model=BRIDGE_MODEL, **kwargs): | ||
| def __init__(self, hass, name=BRIDGE_NAME): | ||
| """Initialize a Bridge object.""" | ||
| super().__init__(name, **kwargs) | ||
| set_accessory_info(self, name, model) | ||
| super().__init__(name) | ||
| set_accessory_info(self, name, model=BRIDGE_MODEL) | ||
| self.hass = hass | ||
|
|
||
| def _set_services(self): | ||
|
|
@@ -130,7 +155,7 @@ def add_paired_client(self, client_uuid, client_public): | |
| def remove_paired_client(self, client_uuid): | ||
| """Override super function to show setup message if unpaired.""" | ||
| super().remove_paired_client(client_uuid) | ||
| show_setup_message(self, self.hass) | ||
| show_setup_message(self.hass, self) | ||
|
|
||
|
|
||
| class HomeDriver(AccessoryDriver): | ||
|
|
||
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
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
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.
Are you sure you never need
configto be passed to the Accessory?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.
About 90% sure that it isn't needed. The intention behind
configwas/is to use it for corner cases (e.g. the alarm_code) or to be able to define which type should be used there so it won't have to be incustomize.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.
Ok, because you used to pass it and stopped with the new code... otherwise all seems similar (hate to ask the obvious, but you did test it? 😄)
Uh oh!
There was an error while loading. Please reload this page.
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.
Test what?
The config was never passed to
super().__init__(), since they haven't been keyword arguments before, only normal ones.**kwargswas there to cover any case that I need to pass more arguments from get_accessory to the HAP-python accessory. However only used for aid.Edit:
I did test all changes for lights at least. That works. The changes in the other types are mostly identical. I also change the same line in the tests. As you know with PR's that change the base structure it's almost impossible to test everything, but I'm quite confident that it won't introduce new errors.