Pyhiveapi icon indicating copy to clipboard operation
Pyhiveapi copied to clipboard

changes to support guest accounts

Open AWare opened this issue 3 years ago β€’ 15 comments

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 getAll with a homeId.
  • 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()

AWare avatar May 15 '22 15:05 AWare

@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 avatar May 18 '22 17:05 AWare

@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 avatar May 18 '22 18:05 KJonline

@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

AWare avatar May 18 '22 19:05 AWare

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.

AWare avatar May 18 '22 23:05 AWare

@KJonline would you be able to give me a hand testing this sometime please?

AWare avatar Jul 25 '22 22:07 AWare

@AWare yep can do. I think there is still some outstanding changes on this?

KJonline avatar Jul 25 '22 22:07 KJonline

I'm not 100% happy with the split between getParams and getHomeIdParam but was having problems building a harness to test it with.

AWare avatar Jul 26 '22 17:07 AWare

@AWare im going to take a look a bit later on tonight

KJonline avatar Jul 26 '22 19:07 KJonline

@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.

AWare avatar Jul 27 '22 21:07 AWare

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 avatar Jul 27 '22 22:07 KJonline

@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

AWare avatar Jul 31 '22 16:07 AWare

@KJonline hi, have you had a chance to look at this yet?

AWare avatar Aug 20 '22 19:08 AWare

@KJonline sorry to bother you, but would you be able to have another look at this please?

AWare avatar Sep 01 '22 07:09 AWare

@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.

martintoreilly avatar Oct 11 '22 15:10 martintoreilly

Sorry, but I won't be continuing to work on this PR.

AWare avatar Nov 01 '22 17:11 AWare