-
Notifications
You must be signed in to change notification settings - Fork 20
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
changes to support guest accounts #42
base: master
Are you sure you want to change the base?
Conversation
@KJonline I'm going to be unavailable for a few weeks from the end of this week as I'm having elbow surgery- and would really like to get this in before I go. can I get a bit of a hand getting this over the line please? |
@AWare unfortunately I’m not in a position to at the minute. Im moving house next week so I need to focus on getting that complete. I can help by giving support over chat. Sorry I can’t be more help. |
@KJonline good luck with the move! if you're happy to run the workflows, I can fix anything they suggest and then we can pick this up when it's mutually convenient |
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.
Just had a scan through and spotted the async version of the API it looks like you haven't updated the all url to remove the hard coded params in favour of using the new getParams function.
Cheers, have handled that and the linter comments. Trying to test it now, using
and getting some weird list index out of range errors on |
@KJonline would you be able to give me a hand testing this sometime please? |
@AWare yep can do. I think there is still some outstanding changes on this? |
I'm not 100% happy with the split between |
@AWare im going to take a look a bit later on tonight |
} | ||
if sendhomeID and self.homeID is not None: | ||
params.update({"homeId": self.homeID}) | ||
return params |
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.
You need and else if here if someone requests to the send the homeId but its actually set to None. to do this you will also need to create a new exception in the Hive exceptions file and import it into this module
return params | |
elif sendhomeID and self.homeID is None: | |
raise HiveInvalidHomeId | |
return params |
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.
This would change the behaviour of the sync api to require a homeId in the case of one home in hive. I've tried to make sure my change only effects cases where a homeID is actually set.
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.
Thinking about it, there's nowhere we don't want to send homeID if it isn't set; except getHomes
, which doesn't mind it being set. So we don't need an arg for it.
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.
What about if your the account owner with a single home and you don’t need to send a homeID.
is your thinking to send one anyway?
@KJonline thanks for the feedback, I've managed to get it working with the async api now, it turns out that where requests turned |
I think the best way for me to help with testing is if I create a new temp branch to merge it into. As the code lives on your repository I don’t have access to pull the code |
@KJonline I think you can just set my fork as a remote, and you should be able to push to this branch too because of my PR. Or, there is a way to check out this pr with refs https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally#modifying-an-inactive-pull-request-locally if you didn't want to push |
@KJonline hi, have you had a chance to look at this yet? |
@KJonline sorry to bother you, but would you be able to have another look at this please? |
set home if set
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.
Please see feedback in sections of code
@@ -210,11 +266,13 @@ def getProducts(self): | |||
|
|||
def getActions(self): | |||
"""Call the get actions endpoint.""" | |||
url = self.urls["base"] + self.urls["actions"] | |||
url = self.urls["all"] |
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.
How come this has been updated to point to all? getDevices & getProducts still points to the individual endpoints. if we can get all data from the all endpoint maybe we should remove the individual endpoints. What do you think?
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.
I have no idea, I did this in July. Sorry.
@@ -222,11 +264,13 @@ async def getProducts(self): | |||
async def getActions(self): | |||
"""Call the get actions endpoint.""" | |||
json_return = {} | |||
url = self.urls["actions"] | |||
url = self.urls["all"] |
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.
Same comment here as the sync one
@@ -101,6 +100,8 @@ def __init__( | |||
) | |||
self.devices = {} | |||
self.deviceList = {} | |||
self.api = API(hiveSession=self, websession=websession) |
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.
Not sure why this has moved? doesn't really matter I don't think, the linter may complain
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.
iirc there's a race condition here. this makes sure that the api is not defined until after session has everything it needs
if self.session is not None: | ||
self.homeID = self.session.config.homeID | ||
|
||
def getParams(self, products=False, devices=False, actions=False): |
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.
I did some testing of the the sync code and the api didn't seem to work with the params when they where booleans. When I changed them to be lower case f and in quotes the api then worked as expected.
def getParams(self, products=False, devices=False, actions=False): | |
def getParams(self, products='false', devices='false', actions='false\): |
The other option would be to the leave the params as booleans and update the dictionary to be as per below converting them to string and lowercasing them.
params = {
"products": str(products).lower(),
"devices": str(devices).lower(),
"actions": str(actions).lower(),
}
"devices": 'true' if devices else 'false', | ||
"actions": 'true' if actions else 'false', | ||
} | ||
if self.homeID: |
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.
You seemed to have catered for it here but not in the sync api
Sorry, but I won't be continuing to work on this PR. |
This adds support for the
homeId
parameter as suggested by @martintoreilly in #32This also moves
homeId
out of urls where used and into the param dict.Caveats:
getAll
with ahomeId
.With some assistance testing this against async I think this should work in ha as afaict
session.config
comes from the integrations config, so by not overwritinghomeID
in the session, this should work?getParams
would have worked nicely ifgetAll
filtered onhomeId
, but as it doesn't- could probably do with a little rethink on my partTested with:
Tested in async mode with