-
Notifications
You must be signed in to change notification settings - Fork 123
Improvements 6 - Driver assignment #105
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
Conversation
|
Few points:
|
I reverted the changes to the encoder and persistence methods.
Is there a reason for it? As far as I see it, accessories can't do anything useful without a driver. That is even less if you consider that the driver handles the event loop.
Maybe we should outsouce them to a entirely new class, similar to the |
Codecov Report
@@ Coverage Diff @@
## dev #105 +/- ##
=========================================
- Coverage 51.04% 50.95% -0.1%
=========================================
Files 15 15
Lines 1340 1315 -25
Branches 140 135 -5
=========================================
- Hits 684 670 -14
+ Misses 642 633 -9
+ Partials 14 12 -2
|
|
They are already. What reason is there for an accessory to exist without the driver. Currently it's just the other way round which complicates thing IMO. Passing the driver to each I will update this PR. That should make it clearer where the benefits are. |
|
What do you mean by "complicates things"? The way I see it is that there are three clear, separate things: (1) A representation of a service (2) the state of the service and (3) a thing which manipulates the state of the service as a result of interactions with the outside world. Currently, the Accessory is both the representation of a service and its state and the driver is the thing that manipulates. What this change proposes is to move the state from the accessory to the driver, which is totally fine, although ideally we should separate it. However, by forcing the accessory to have a driver, we essentially need to have all three things created to get functionality even from only one of them. For example, to test the Accessory I have to have a driver. I don't see this is as bringing any benefits. Right now I can have and Accessory and a Driver separately, potentially reusing and substituting whatever I want individually. |
|
Let me step back a few points. The problem I see with the current setup is that we create the event loop within the driver (which is the right call IMO). As we move more and more methods to async. Eventually nearly all objects will need a reference to the To be honest I took this lesson from Home Assistant as well. Their we have the
Their is nothing against that. The question that remains however is how much sense does it make to have a object that is totally separated, but can't do anything since it requires some setup (eg.
You're right their. However currently you need an accessory to test the top level driver. HA has a special function to handle this
I still plan on doing this. The way I see it the hierarchy for |
|
Will have another look when you resolve the conflicts, but I think we are mostly there. |
* Driver now passed to accessory as argument * Top level accessory then added to driver with 'add_accessory'
|
@ikalchev I have updated this PR. The main ideas some of which we already discussed:
Additional changes: Since this PR is already quite big (even though about half of the changes are related to tests), I did not include the |
ikalchev
left a comment
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.
Looks good. However, why do you want to remove the standalone default loaders, i.e. why do we assume that the user will be using these only inside the driver/acc? It is perfectly fine for the user to have a method get services which are then fed to the acc using add_service. Let's now burn down bridges for users and let them decide if they want a different workflow than ours. Also, if we don't remove the get_x_loader methods, this is one breaking change less.
pyhap/loader.py
Outdated
| _loader = None | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def read_file(path): |
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.
Actually json_file_to_dict
| Accessory(DRIVER, 'Test Accessory') | ||
|
|
||
|
|
||
| class TestAccessory: |
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.
Why are we removing the classes? This prevents you from running tests only from a single test class. Is the performance issue really big - there only a handful of methods?
I've reverted them, so this PR can get merged. The original idea was just to reduce maintenance costs and avoid storing an object in a module, since this is kind of a bad practice for python.
I changed it back as well. Only added
You couldn't run them separately before either. Since The |
During my improvement PR's I noticed that we assign may things to each accessory although they are only needed once (at the driver level). Especially for bridged accessories that is mostly unnecessary. This PR should be a first step in reversing this behavior.
Instead of assigning the accessory to the driver, I think that I would make much more sense to assign the driver to each accessory and later add the top level one to the driver.
To-Do
accessory.set_sentineldriver.run_sentinel,driver.aio_stop_eventanddriver.event_loopMaybe: Assignkeys,pincode,macto driver instead.Note: All these changes assume that we stick to the current version, where one driver only handles one top level accessory.
@ikalchev What do you think this?