pyhive-integration 0.5.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyhive_integration-0.5.17/LICENSE +21 -0
- pyhive_integration-0.5.17/MANIFEST.in +4 -0
- pyhive_integration-0.5.17/PKG-INFO +32 -0
- pyhive_integration-0.5.17/README.md +15 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/__init__.py +11 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/action.py +121 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/alarm.py +128 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/api/__init__.py +1 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/api/hive_api.py +300 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/api/hive_async_api.py +346 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/api/hive_auth.py +611 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/api/hive_auth_async.py +651 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/camera.py +185 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/data/alarm.json +53 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/data/camera.json +17 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/data/data.json +4542 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/device_attributes.py +102 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/heating.py +519 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/__init__.py +4 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/const.py +170 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/debugger.py +64 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/hive_exceptions.py +82 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/hive_helper.py +213 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/hivedataclasses.py +21 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/logger.py +36 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/helper/map.py +14 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/hive.py +139 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/hotwater.py +275 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/hub.py +85 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/light.py +441 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/plug.py +217 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/sensor.py +145 -0
- pyhive_integration-0.5.17/pyhiveapi/apyhiveapi/session.py +584 -0
- pyhive_integration-0.5.17/pyhiveapi/pyhive_integration.egg-info/PKG-INFO +32 -0
- pyhive_integration-0.5.17/pyhiveapi/pyhive_integration.egg-info/SOURCES.txt +43 -0
- pyhive_integration-0.5.17/pyhiveapi/pyhive_integration.egg-info/dependency_links.txt +1 -0
- pyhive_integration-0.5.17/pyhiveapi/pyhive_integration.egg-info/requires.txt +11 -0
- pyhive_integration-0.5.17/pyhiveapi/pyhive_integration.egg-info/top_level.txt +1 -0
- pyhive_integration-0.5.17/pyproject.toml +3 -0
- pyhive_integration-0.5.17/requirements.txt +8 -0
- pyhive_integration-0.5.17/requirements_test.txt +1 -0
- pyhive_integration-0.5.17/setup.cfg +66 -0
- pyhive_integration-0.5.17/setup.py +45 -0
- pyhive_integration-0.5.17/tests/test_hub.py +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Pyhive
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyhive-integration
|
|
3
|
+
Version: 0.5.17
|
|
4
|
+
Summary: A Python library to interface with the Hive API
|
|
5
|
+
Home-page: https://github.com/Pyhive/pyhiveapi
|
|
6
|
+
Author: KJonline24
|
|
7
|
+
Author-email: khole_47@icloud.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/Pyhive/Pyhiveapi
|
|
10
|
+
Project-URL: Issue tracker, https://github.com/Pyhive/Pyhiveapi/issues
|
|
11
|
+
Keywords: Hive API Library
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Requires-Python: >=3.6
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pre-commit
|
|
22
|
+
Requires-Dist: boto3>=1.16.10
|
|
23
|
+
Requires-Dist: botocore>=1.19.10
|
|
24
|
+
Requires-Dist: requests
|
|
25
|
+
Requires-Dist: aiohttp
|
|
26
|
+
Requires-Dist: pyquery
|
|
27
|
+
Requires-Dist: unasync
|
|
28
|
+
Requires-Dist: loguru
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: tox; extra == "dev"
|
|
31
|
+
Dynamic: provides-extra
|
|
32
|
+
Dynamic: requires-dist
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
 
|
|
3
|
+
|
|
4
|
+
# Introduction
|
|
5
|
+
This is a library which intefaces with the Hive smart home platform.
|
|
6
|
+
This library is built mainly to integrate with the Home Assistant platform,
|
|
7
|
+
but it can also be used independently (See examples below.)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Examples
|
|
11
|
+
Here are examples and documentation on how to use the library independently.
|
|
12
|
+
|
|
13
|
+
https://pyhass.github.io/pyhiveapi.docs/ [WIP]
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""__init__.py."""
|
|
2
|
+
# pylint: skip-file
|
|
3
|
+
if __name__ == "pyhiveapi":
|
|
4
|
+
from .api.hive_api import HiveApi as API # noqa: F401
|
|
5
|
+
from .api.hive_auth import HiveAuth as Auth # noqa: F401
|
|
6
|
+
else:
|
|
7
|
+
from .api.hive_async_api import HiveApiAsync as API # noqa: F401
|
|
8
|
+
from .api.hive_auth_async import HiveAuthAsync as Auth # noqa: F401
|
|
9
|
+
|
|
10
|
+
from .helper.const import SMS_REQUIRED # noqa: F401
|
|
11
|
+
from .hive import Hive # noqa: F401
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Hive Action Module."""
|
|
2
|
+
# pylint: skip-file
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class HiveAction:
|
|
6
|
+
"""Hive Action Code.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
object: Return hive action object.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
actionType = "Actions"
|
|
13
|
+
|
|
14
|
+
def __init__(self, session: object = None):
|
|
15
|
+
"""Initialise Action.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
session (object, optional): session to interact with hive account. Defaults to None.
|
|
19
|
+
"""
|
|
20
|
+
self.session = session
|
|
21
|
+
|
|
22
|
+
async def getAction(self, device: dict):
|
|
23
|
+
"""Action device to update.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
device (dict): Device to be updated.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
dict: Updated device.
|
|
30
|
+
"""
|
|
31
|
+
dev_data = {}
|
|
32
|
+
|
|
33
|
+
if device["hiveID"] in self.data["action"]:
|
|
34
|
+
dev_data = {
|
|
35
|
+
"hiveID": device["hiveID"],
|
|
36
|
+
"hiveName": device["hiveName"],
|
|
37
|
+
"hiveType": device["hiveType"],
|
|
38
|
+
"haName": device["haName"],
|
|
39
|
+
"haType": device["haType"],
|
|
40
|
+
"status": {"state": await self.getState(device)},
|
|
41
|
+
"power_usage": None,
|
|
42
|
+
"deviceData": {},
|
|
43
|
+
"custom": device.get("custom", None),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
self.session.devices.update({device["hiveID"]: dev_data})
|
|
47
|
+
return self.session.devices[device["hiveID"]]
|
|
48
|
+
else:
|
|
49
|
+
exists = self.session.data.actions.get("hiveID", False)
|
|
50
|
+
if exists is False:
|
|
51
|
+
return "REMOVE"
|
|
52
|
+
return device
|
|
53
|
+
|
|
54
|
+
async def getState(self, device: dict):
|
|
55
|
+
"""Get action state.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
device (dict): Device to get state of.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
str: Return state.
|
|
62
|
+
"""
|
|
63
|
+
final = None
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
data = self.session.data.actions[device["hiveID"]]
|
|
67
|
+
final = data["enabled"]
|
|
68
|
+
except KeyError as e:
|
|
69
|
+
await self.session.log.error(e)
|
|
70
|
+
|
|
71
|
+
return final
|
|
72
|
+
|
|
73
|
+
async def setStatusOn(self, device: dict):
|
|
74
|
+
"""Set action turn on.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
device (dict): Device to set state of.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
boolean: True/False if successful.
|
|
81
|
+
"""
|
|
82
|
+
import json
|
|
83
|
+
|
|
84
|
+
final = False
|
|
85
|
+
|
|
86
|
+
if device["hiveID"] in self.session.data.actions:
|
|
87
|
+
await self.session.hiveRefreshTokens()
|
|
88
|
+
data = self.session.data.actions[device["hiveID"]]
|
|
89
|
+
data.update({"enabled": True})
|
|
90
|
+
send = json.dumps(data)
|
|
91
|
+
resp = await self.session.api.setAction(device["hiveID"], send)
|
|
92
|
+
if resp["original"] == 200:
|
|
93
|
+
final = True
|
|
94
|
+
await self.session.getDevices(device["hiveID"])
|
|
95
|
+
|
|
96
|
+
return final
|
|
97
|
+
|
|
98
|
+
async def setStatusOff(self, device: dict):
|
|
99
|
+
"""Set action to turn off.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
device (dict): Device to set state of.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
boolean: True/False if successful.
|
|
106
|
+
"""
|
|
107
|
+
import json
|
|
108
|
+
|
|
109
|
+
final = False
|
|
110
|
+
|
|
111
|
+
if device["hiveID"] in self.session.data.actions:
|
|
112
|
+
await self.session.hiveRefreshTokens()
|
|
113
|
+
data = self.session.data.actions[device["hiveID"]]
|
|
114
|
+
data.update({"enabled": False})
|
|
115
|
+
send = json.dumps(data)
|
|
116
|
+
resp = await self.session.api.setAction(device["hiveID"], send)
|
|
117
|
+
if resp["original"] == 200:
|
|
118
|
+
final = True
|
|
119
|
+
await self.session.getDevices(device["hiveID"])
|
|
120
|
+
|
|
121
|
+
return final
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Hive Alarm Module."""
|
|
2
|
+
# pylint: skip-file
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class HiveHomeShield:
|
|
6
|
+
"""Hive homeshield alarm.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
object: Hive homeshield
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
alarmType = "Alarm"
|
|
13
|
+
|
|
14
|
+
async def getMode(self):
|
|
15
|
+
"""Get current mode of the alarm.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
str: Mode if the alarm [armed_home, armed_away, armed_night]
|
|
19
|
+
"""
|
|
20
|
+
state = None
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
data = self.session.data.alarm
|
|
24
|
+
state = data["mode"]
|
|
25
|
+
except KeyError as e:
|
|
26
|
+
await self.session.log.error(e)
|
|
27
|
+
|
|
28
|
+
return state
|
|
29
|
+
|
|
30
|
+
async def getState(self, device: dict):
|
|
31
|
+
"""Get the alarm triggered state.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
boolean: True/False if alarm is triggered.
|
|
35
|
+
"""
|
|
36
|
+
state = None
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
data = self.session.data.devices[device["hiveID"]]
|
|
40
|
+
state = data["state"]["alarmActive"]
|
|
41
|
+
except KeyError as e:
|
|
42
|
+
await self.session.log.error(e)
|
|
43
|
+
|
|
44
|
+
return state
|
|
45
|
+
|
|
46
|
+
async def setMode(self, device: dict, mode: str):
|
|
47
|
+
"""Set the alarm mode.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
device (dict): Alarm device.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
boolean: True/False if successful.
|
|
54
|
+
"""
|
|
55
|
+
final = False
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
device["hiveID"] in self.session.data.devices
|
|
59
|
+
and device["deviceData"]["online"]
|
|
60
|
+
):
|
|
61
|
+
await self.session.hiveRefreshTokens()
|
|
62
|
+
resp = await self.session.api.setAlarm(mode=mode)
|
|
63
|
+
if resp["original"] == 200:
|
|
64
|
+
final = True
|
|
65
|
+
await self.session.getAlarm()
|
|
66
|
+
|
|
67
|
+
return final
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Alarm(HiveHomeShield):
|
|
71
|
+
"""Home assistant alarm.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
HiveHomeShield (object): Class object.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self, session: object = None):
|
|
78
|
+
"""Initialise alarm.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
session (object, optional): Used to interact with the hive account. Defaults to None.
|
|
82
|
+
"""
|
|
83
|
+
self.session = session
|
|
84
|
+
|
|
85
|
+
async def getAlarm(self, device: dict):
|
|
86
|
+
"""Get alarm data.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
device (dict): Device to update.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
dict: Updated device.
|
|
93
|
+
"""
|
|
94
|
+
device["deviceData"].update(
|
|
95
|
+
{"online": await self.session.attr.onlineOffline(device["device_id"])}
|
|
96
|
+
)
|
|
97
|
+
dev_data = {}
|
|
98
|
+
|
|
99
|
+
if device["deviceData"]["online"]:
|
|
100
|
+
self.session.helper.deviceRecovered(device["device_id"])
|
|
101
|
+
data = self.session.data.devices[device["device_id"]]
|
|
102
|
+
dev_data = {
|
|
103
|
+
"hiveID": device["hiveID"],
|
|
104
|
+
"hiveName": device["hiveName"],
|
|
105
|
+
"hiveType": device["hiveType"],
|
|
106
|
+
"haName": device["haName"],
|
|
107
|
+
"haType": device["haType"],
|
|
108
|
+
"device_id": device["device_id"],
|
|
109
|
+
"device_name": device["device_name"],
|
|
110
|
+
"status": {
|
|
111
|
+
"state": await self.getState(device),
|
|
112
|
+
"mode": await self.getMode(),
|
|
113
|
+
},
|
|
114
|
+
"deviceData": data.get("props", None),
|
|
115
|
+
"parentDevice": data.get("parent", None),
|
|
116
|
+
"custom": device.get("custom", None),
|
|
117
|
+
"attributes": await self.session.attr.stateAttributes(
|
|
118
|
+
device["device_id"], device["hiveType"]
|
|
119
|
+
),
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
self.session.devices.update({device["hiveID"]: dev_data})
|
|
123
|
+
return self.session.devices[device["hiveID"]]
|
|
124
|
+
else:
|
|
125
|
+
await self.session.log.errorCheck(
|
|
126
|
+
device["device_id"], "ERROR", device["deviceData"]["online"]
|
|
127
|
+
)
|
|
128
|
+
return device
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""__init__.py file."""
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""Hive API Module."""
|
|
2
|
+
# pylint: skip-file
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
import urllib3
|
|
7
|
+
from pyquery import PyQuery
|
|
8
|
+
|
|
9
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HiveApi:
|
|
13
|
+
"""Hive API Code."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, hiveSession=None, websession=None, token=None):
|
|
16
|
+
"""Hive API initialisation."""
|
|
17
|
+
self.cameraBaseUrl = "prod.hcam.bgchtest.info"
|
|
18
|
+
self.urls = {
|
|
19
|
+
"properties": "https://sso.hivehome.com/",
|
|
20
|
+
"login": "https://beekeeper.hivehome.com/1.0/cognito/login",
|
|
21
|
+
"refresh": "https://beekeeper.hivehome.com/1.0/cognito/refresh-token",
|
|
22
|
+
"long_lived": "https://api.prod.bgchprod.info/omnia/accessTokens",
|
|
23
|
+
"base": "https://beekeeper-uk.hivehome.com/1.0",
|
|
24
|
+
"weather": "https://weather.prod.bgchprod.info/weather",
|
|
25
|
+
"holiday_mode": "/holiday-mode",
|
|
26
|
+
"all": "/nodes/all?products=true&devices=true&actions=true",
|
|
27
|
+
"alarm": "/security-lite?homeId=",
|
|
28
|
+
"cameraImages": f"https://event-history-service.{self.cameraBaseUrl}/v1/events/cameras?latest=true&cameraId={{0}}",
|
|
29
|
+
"cameraRecordings": f"https://event-history-service.{self.cameraBaseUrl}/v1/playlist/cameras/{{0}}/events/{{1}}.m3u8",
|
|
30
|
+
"devices": "/devices",
|
|
31
|
+
"products": "/products",
|
|
32
|
+
"actions": "/actions",
|
|
33
|
+
"nodes": "/nodes/{0}/{1}",
|
|
34
|
+
}
|
|
35
|
+
self.timeout = 10
|
|
36
|
+
self.json_return = {
|
|
37
|
+
"original": "No response to Hive API request",
|
|
38
|
+
"parsed": "No response to Hive API request",
|
|
39
|
+
}
|
|
40
|
+
self.session = hiveSession
|
|
41
|
+
self.token = token
|
|
42
|
+
|
|
43
|
+
def request(self, type, url, jsc=None, camera=False):
|
|
44
|
+
"""Make API request."""
|
|
45
|
+
if self.session is not None:
|
|
46
|
+
if camera:
|
|
47
|
+
self.headers = {
|
|
48
|
+
"content-type": "application/json",
|
|
49
|
+
"Accept": "*/*",
|
|
50
|
+
"Authorization": f"Bearer {self.session.tokens.tokenData['token']}",
|
|
51
|
+
"x-jwt-token": self.session.tokens.tokenData["token"],
|
|
52
|
+
}
|
|
53
|
+
else:
|
|
54
|
+
self.headers = {
|
|
55
|
+
"content-type": "application/json",
|
|
56
|
+
"Accept": "*/*",
|
|
57
|
+
"authorization": self.session.tokens.tokenData["token"],
|
|
58
|
+
}
|
|
59
|
+
else:
|
|
60
|
+
if camera:
|
|
61
|
+
self.headers = {
|
|
62
|
+
"content-type": "application/json",
|
|
63
|
+
"Accept": "*/*",
|
|
64
|
+
"Authorization": f"Bearer {self.token}",
|
|
65
|
+
"x-jwt-token": self.token,
|
|
66
|
+
}
|
|
67
|
+
else:
|
|
68
|
+
self.headers = {
|
|
69
|
+
"content-type": "application/json",
|
|
70
|
+
"Accept": "*/*",
|
|
71
|
+
"authorization": self.token,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if type == "GET":
|
|
75
|
+
return requests.get(
|
|
76
|
+
url=url, headers=self.headers, data=jsc, timeout=self.timeout
|
|
77
|
+
)
|
|
78
|
+
if type == "POST":
|
|
79
|
+
return requests.post(
|
|
80
|
+
url=url, headers=self.headers, data=jsc, timeout=self.timeout
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def refreshTokens(self, tokens={}):
|
|
84
|
+
"""Get new session tokens - DEPRECATED NOW BY AWS TOKEN MANAGEMENT."""
|
|
85
|
+
url = self.urls["refresh"]
|
|
86
|
+
if self.session is not None:
|
|
87
|
+
tokens = self.session.tokens.tokenData
|
|
88
|
+
jsc = (
|
|
89
|
+
"{"
|
|
90
|
+
+ ",".join(
|
|
91
|
+
('"' + str(i) + '": ' '"' + str(t) + '" ' for i, t in tokens.items())
|
|
92
|
+
)
|
|
93
|
+
+ "}"
|
|
94
|
+
)
|
|
95
|
+
try:
|
|
96
|
+
info = self.request("POST", url, jsc)
|
|
97
|
+
data = json.loads(info.text)
|
|
98
|
+
if "token" in data and self.session:
|
|
99
|
+
self.session.updateTokens(data)
|
|
100
|
+
self.urls.update({"base": data["platform"]["endpoint"]})
|
|
101
|
+
self.urls.update({"camera": data["platform"]["cameraPlatform"]})
|
|
102
|
+
self.json_return.update({"original": info.status_code})
|
|
103
|
+
self.json_return.update({"parsed": info.json()})
|
|
104
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
105
|
+
self.error()
|
|
106
|
+
|
|
107
|
+
return self.json_return
|
|
108
|
+
|
|
109
|
+
def getLoginInfo(self):
|
|
110
|
+
"""Get login properties to make the login request."""
|
|
111
|
+
url = self.urls["properties"]
|
|
112
|
+
try:
|
|
113
|
+
data = requests.get(url=url, verify=False, timeout=self.timeout)
|
|
114
|
+
html = PyQuery(data.content)
|
|
115
|
+
json_data = json.loads(
|
|
116
|
+
'{"'
|
|
117
|
+
+ (html("script:first").text())
|
|
118
|
+
.replace(",", ', "')
|
|
119
|
+
.replace("=", '":')
|
|
120
|
+
.replace("window.", "")
|
|
121
|
+
+ "}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
loginData = {}
|
|
125
|
+
loginData.update({"UPID": json_data["HiveSSOPoolId"]})
|
|
126
|
+
loginData.update({"CLIID": json_data["HiveSSOPublicCognitoClientId"]})
|
|
127
|
+
loginData.update({"REGION": json_data["HiveSSOPoolId"]})
|
|
128
|
+
return loginData
|
|
129
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
130
|
+
self.error()
|
|
131
|
+
|
|
132
|
+
def getAll(self):
|
|
133
|
+
"""Build and query all endpoint."""
|
|
134
|
+
json_return = {}
|
|
135
|
+
url = self.urls["base"] + self.urls["all"]
|
|
136
|
+
try:
|
|
137
|
+
info = self.request("GET", url)
|
|
138
|
+
json_return.update({"original": info.status_code})
|
|
139
|
+
json_return.update({"parsed": info.json()})
|
|
140
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
141
|
+
self.error()
|
|
142
|
+
|
|
143
|
+
return json_return
|
|
144
|
+
|
|
145
|
+
def getAlarm(self, homeID=None):
|
|
146
|
+
"""Build and query alarm endpoint."""
|
|
147
|
+
if self.session is not None:
|
|
148
|
+
homeID = self.session.config.homeID
|
|
149
|
+
url = self.urls["base"] + self.urls["alarm"] + homeID
|
|
150
|
+
try:
|
|
151
|
+
info = self.request("GET", url)
|
|
152
|
+
self.json_return.update({"original": info.status_code})
|
|
153
|
+
self.json_return.update({"parsed": info.json()})
|
|
154
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
155
|
+
self.error()
|
|
156
|
+
|
|
157
|
+
return self.json_return
|
|
158
|
+
|
|
159
|
+
def getCameraImage(self, device=None, accessToken=None):
|
|
160
|
+
"""Build and query camera endpoint."""
|
|
161
|
+
json_return = {}
|
|
162
|
+
url = self.urls["cameraImages"].format(device["props"]["hardwareIdentifier"])
|
|
163
|
+
try:
|
|
164
|
+
info = self.request("GET", url, camera=True)
|
|
165
|
+
json_return.update({"original": info.status_code})
|
|
166
|
+
json_return.update({"parsed": info.json()})
|
|
167
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
168
|
+
self.error()
|
|
169
|
+
|
|
170
|
+
return json_return
|
|
171
|
+
|
|
172
|
+
def getCameraRecording(self, device=None, eventId=None):
|
|
173
|
+
"""Build and query camera endpoint."""
|
|
174
|
+
json_return = {}
|
|
175
|
+
url = self.urls["cameraRecordings"].format(
|
|
176
|
+
device["props"]["hardwareIdentifier"], eventId
|
|
177
|
+
)
|
|
178
|
+
try:
|
|
179
|
+
info = self.request("GET", url, camera=True)
|
|
180
|
+
json_return.update({"original": info.status_code})
|
|
181
|
+
json_return.update({"parsed": info.text.split("\n")[3]})
|
|
182
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
183
|
+
self.error()
|
|
184
|
+
|
|
185
|
+
return json_return
|
|
186
|
+
|
|
187
|
+
def getDevices(self):
|
|
188
|
+
"""Call the get devices endpoint."""
|
|
189
|
+
url = self.urls["base"] + self.urls["devices"]
|
|
190
|
+
try:
|
|
191
|
+
response = self.request("GET", url)
|
|
192
|
+
self.json_return.update({"original": response.status_code})
|
|
193
|
+
self.json_return.update({"parsed": response.json()})
|
|
194
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
195
|
+
self.error()
|
|
196
|
+
|
|
197
|
+
return self.json_return
|
|
198
|
+
|
|
199
|
+
def getProducts(self):
|
|
200
|
+
"""Call the get products endpoint."""
|
|
201
|
+
url = self.urls["base"] + self.urls["products"]
|
|
202
|
+
try:
|
|
203
|
+
response = self.request("GET", url)
|
|
204
|
+
self.json_return.update({"original": response.status_code})
|
|
205
|
+
self.json_return.update({"parsed": response.json()})
|
|
206
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
207
|
+
self.error()
|
|
208
|
+
|
|
209
|
+
return self.json_return
|
|
210
|
+
|
|
211
|
+
def getActions(self):
|
|
212
|
+
"""Call the get actions endpoint."""
|
|
213
|
+
url = self.urls["base"] + self.urls["actions"]
|
|
214
|
+
try:
|
|
215
|
+
response = self.request("GET", url)
|
|
216
|
+
self.json_return.update({"original": response.status_code})
|
|
217
|
+
self.json_return.update({"parsed": response.json()})
|
|
218
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
219
|
+
self.error()
|
|
220
|
+
|
|
221
|
+
return self.json_return
|
|
222
|
+
|
|
223
|
+
def motionSensor(self, sensor, fromepoch, toepoch):
|
|
224
|
+
"""Call a way to get motion sensor info."""
|
|
225
|
+
url = (
|
|
226
|
+
self.urls["base"]
|
|
227
|
+
+ self.urls["products"]
|
|
228
|
+
+ "/"
|
|
229
|
+
+ sensor["type"]
|
|
230
|
+
+ "/"
|
|
231
|
+
+ sensor["id"]
|
|
232
|
+
+ "/events?from="
|
|
233
|
+
+ str(fromepoch)
|
|
234
|
+
+ "&to="
|
|
235
|
+
+ str(toepoch)
|
|
236
|
+
)
|
|
237
|
+
try:
|
|
238
|
+
response = self.request("GET", url)
|
|
239
|
+
self.json_return.update({"original": response.status_code})
|
|
240
|
+
self.json_return.update({"parsed": response.json()})
|
|
241
|
+
except (OSError, RuntimeError, ZeroDivisionError):
|
|
242
|
+
self.error()
|
|
243
|
+
|
|
244
|
+
return self.json_return
|
|
245
|
+
|
|
246
|
+
def getWeather(self, weather_url):
|
|
247
|
+
"""Call endpoint to get local weather from Hive API."""
|
|
248
|
+
t_url = self.urls["weather"] + weather_url
|
|
249
|
+
url = t_url.replace(" ", "%20")
|
|
250
|
+
try:
|
|
251
|
+
response = self.request("GET", url)
|
|
252
|
+
self.json_return.update({"original": response.status_code})
|
|
253
|
+
self.json_return.update({"parsed": response.json()})
|
|
254
|
+
except (OSError, RuntimeError, ZeroDivisionError, ConnectionError):
|
|
255
|
+
self.error()
|
|
256
|
+
|
|
257
|
+
return self.json_return
|
|
258
|
+
|
|
259
|
+
def setState(self, n_type, n_id, **kwargs):
|
|
260
|
+
"""Set the state of a Device."""
|
|
261
|
+
jsc = (
|
|
262
|
+
"{"
|
|
263
|
+
+ ",".join(
|
|
264
|
+
('"' + str(i) + '": ' '"' + str(t) + '" ' for i, t in kwargs.items())
|
|
265
|
+
)
|
|
266
|
+
+ "}"
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
url = self.urls["base"] + self.urls["nodes"].format(n_type, n_id)
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
response = self.request("POST", url, jsc)
|
|
273
|
+
self.json_return.update({"original": response.status_code})
|
|
274
|
+
self.json_return.update({"parsed": response.json()})
|
|
275
|
+
except (OSError, RuntimeError, ZeroDivisionError, ConnectionError):
|
|
276
|
+
self.error()
|
|
277
|
+
|
|
278
|
+
return self.json_return
|
|
279
|
+
|
|
280
|
+
def setAction(self, n_id, data):
|
|
281
|
+
"""Set the state of a Action."""
|
|
282
|
+
jsc = data
|
|
283
|
+
url = self.urls["base"] + self.urls["actions"] + "/" + n_id
|
|
284
|
+
try:
|
|
285
|
+
response = self.request("POST", url, jsc)
|
|
286
|
+
self.json_return.update({"original": response.status_code})
|
|
287
|
+
self.json_return.update({"parsed": response.json()})
|
|
288
|
+
except (OSError, RuntimeError, ZeroDivisionError, ConnectionError):
|
|
289
|
+
self.error()
|
|
290
|
+
|
|
291
|
+
return self.json_return
|
|
292
|
+
|
|
293
|
+
def error(self):
|
|
294
|
+
"""An error has occurred interacting with the Hive API."""
|
|
295
|
+
self.json_return.update({"original": "Error making API call"})
|
|
296
|
+
self.json_return.update({"parsed": "Error making API call"})
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class UnknownConfig(Exception):
|
|
300
|
+
"""Unknown API config."""
|