changes to support guest accounts
This adds support for the homeId parameter as suggested by @martintoreilly in #32
This also moves homeId out of urls where used and into the param dict.
Caveats:
- Devices and products are not filtered on
getAllwith ahomeId. - I wasn't able to use the async api directly.
- I only have access to a guest hive account, so can't test parity.
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 overwriting homeID in the session, this should work?
getParams would have worked nicely if getAll filtered on homeId, but as it doesn't- could probably do with a little rethink on my part
Tested with:
import pyhiveapi as Hive
tokens = {}
hive_auth = Hive.Auth(π,π)
authData = hive_auth.login()
session = authData["AuthenticationResult"]
tokens.update({"token": session["IdToken"]})
tokens.update({"refreshToken": session["RefreshToken"]})
tokens.update({"accessToken": session["AccessToken"]})
api = Hive.API(token=session["IdToken"])
api.getProducts()
api.getDevices()
api.setHome(π)
api.getProducts()
api.getDevices()
Tested in async mode with
import apyhiveapi as Hive
hiveSession = Hive.session.HiveSession(username="π", password="π")
await hiveSession.login()
api = hiveSession.api
await api.getHomes()
await api.getProducts()
api.setHome("π")
await api.getHomes()
await api.getProducts()
@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
Cheers, have handled that and the linter comments.
Trying to test it now, using python3 -m asyncio and the following:
import apyhiveapi as Hive
hiveSession = Hive.session.HiveSession(username="", password="")
await hiveSession.login()
api = hiveSession.api
await api.getProducts()
api.setHome("")
await api.getProducts()
and getting some weird list index out of range errors on login()- which I'll revisit tomorrow.
@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 getParams and getHomeIdParam but was having problems building a harness to test it with.
@AWare im going to take a look a bit later on tonight
@KJonline thanks for the feedback, I've managed to get it working with the async api now, it turns out that where requests turned key: True into key=true, aiohttp turned it into an exception instead. I've updated the description with my test code.
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?
@AWare @KJonline I can try and find some time this weekend to look at this / test if useful? I've an owner and guest account for my home.
Sorry, but I won't be continuing to work on this PR.