Skip to content

Commit 2a6a09a

Browse files
author
Khole
authored
Update and rename README.txt to README.md
1 parent f6655f1 commit 2a6a09a

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
3+
# Introduction
4+
This is a libary which intefaces with the Hive smart home platform.
5+
This libary is built for to integrate with the Home Assistant platform,
6+
but can be used independantly (See examples below.)
7+
8+
9+
## Examples
10+
Below are examples on how to use the libary independantly.
11+
12+
### Login
13+
Below is an example how to login to Hive with 2FA if needed
14+
and get a session token.
15+
16+
```Python
17+
import pyhiveapi as Hive
18+
19+
tokens = {}
20+
auth = Hive.HiveAuth('username', 'password')
21+
session = auth.login()
22+
if session.get("ChallengeName") == Hive.SMS_REQUIRED:
23+
# Complete SMS 2FA.
24+
code = input("Enter your 2FA code: ")
25+
session = auth.sms_2fa(code, session)
26+
27+
if 'AuthenticationResult' in session:
28+
session = session['AuthenticationResult']
29+
tokens.update(
30+
{"token": session["IdToken"]})
31+
tokens.update(
32+
{"refreshToken": session["RefreshToken"]})
33+
tokens.update(
34+
{"accessToken": session["AccessToken"]})
35+
else:
36+
raise Hive.NoApiToken
37+
```
38+
39+
### Refresh Tokens
40+
Below is an example how to refresh your session tokens
41+
after they have expired
42+
43+
```Python
44+
api = Hive.HiveApi()
45+
newTokens = api.refreshTokens(tokens)
46+
if newTokens['original'] == 200:
47+
tokens.update(
48+
{"token": newTokens['parsed']["token"]})
49+
tokens.update(
50+
{"refreshToken": newTokens['parsed']["refreshToken"]})
51+
tokens.update(
52+
{"accessToken": newTokens['parsed']["accessToken"]})
53+
else:
54+
raise Hive.NoApiToken
55+
```
56+
57+
### Get Hive Data
58+
Below is an example how to data from the Hive platform
59+
using the session token aquired from login.
60+
61+
```Python
62+
api = Hive.HiveApi()
63+
data = api.getAllData(tokens["token"])
64+
```

README.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)