livisi 0.0.1__py3-none-any.whl → 0.0.20__py3-none-any.whl
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.
- livisi/__init__.py +4 -93
- livisi/aiolivisi.py +270 -0
- livisi/const.py +40 -0
- livisi/errors.py +20 -0
- livisi/livisi_event.py +19 -0
- livisi/websocket.py +112 -0
- livisi-0.0.20.dist-info/LICENSE +201 -0
- livisi-0.0.20.dist-info/METADATA +225 -0
- livisi-0.0.20.dist-info/RECORD +11 -0
- livisi/livisi_connector.py +0 -508
- livisi/livisi_const.py +0 -30
- livisi/livisi_controller.py +0 -17
- livisi/livisi_device.py +0 -53
- livisi/livisi_errors.py +0 -124
- livisi/livisi_json_util.py +0 -23
- livisi/livisi_websocket.py +0 -86
- livisi/livisi_websocket_event.py +0 -13
- livisi-0.0.1.dist-info/LICENSE +0 -0
- livisi-0.0.1.dist-info/METADATA +0 -20
- livisi-0.0.1.dist-info/RECORD +0 -14
- {livisi-0.0.1.dist-info → livisi-0.0.20.dist-info}/WHEEL +0 -0
- {livisi-0.0.1.dist-info → livisi-0.0.20.dist-info}/top_level.txt +0 -0
livisi/livisi_errors.py
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
"""Errors for the Livisi Smart Home component."""
|
2
|
-
|
3
|
-
# Taken from https://developer.services-smarthome.de/api_reference/errorcodes/
|
4
|
-
ERROR_CODES = {
|
5
|
-
# General Errors
|
6
|
-
1000: "An unknown error has occurred.",
|
7
|
-
1001: "Service unavailable.",
|
8
|
-
1002: "Service timeout.",
|
9
|
-
1003: "Internal API error.",
|
10
|
-
1004: "SHC invalid operation.",
|
11
|
-
1005: "Missing argument or wrong value.",
|
12
|
-
1006: "Service too busy.",
|
13
|
-
1007: "Unsupported request.",
|
14
|
-
1008: "Precondition failed.",
|
15
|
-
# Authentication and Authorization Errors
|
16
|
-
2000: "An unknown error has occurred during Authentication or Authorization process.",
|
17
|
-
2001: "Access not allowed.",
|
18
|
-
2002: "Invalid token request.",
|
19
|
-
2003: "Invalid client credentials.",
|
20
|
-
2004: "The token signature is invalid.",
|
21
|
-
2005: "Failed to initialize user session.",
|
22
|
-
2006: "A connection already exists for the current session.",
|
23
|
-
2007: "The lifetime of the token has expired.",
|
24
|
-
2008: "Login attempted from a different client provider.",
|
25
|
-
2009: "Invalid user credentials.",
|
26
|
-
2010: "Controller access not allowed.",
|
27
|
-
2011: "Insufficient permissions.",
|
28
|
-
2012: "Session not found.",
|
29
|
-
2013: "Account temporary locked.",
|
30
|
-
# Entities Errors
|
31
|
-
3000: "The requested entity does not exist.",
|
32
|
-
3001: "The provided request content is invalid and can't be parsed.",
|
33
|
-
3002: "No change performed.",
|
34
|
-
3003: "The provided entity already exists.",
|
35
|
-
3004: "The provided interaction is not valid.",
|
36
|
-
3005: "Too many entities of this type.",
|
37
|
-
# Products Errors
|
38
|
-
3500: "Premium Services can't be directly enabled.",
|
39
|
-
3501: "Cannot remove a product that was paid.",
|
40
|
-
# Actions Errors
|
41
|
-
4000: "The triggered action is invalid.",
|
42
|
-
4001: "Invalid parameter.",
|
43
|
-
4002: "Permission to trigger action not allowed.",
|
44
|
-
4003: "Unsupported action type.",
|
45
|
-
# Configuration Errors
|
46
|
-
5000: "The configuration could not be updated.",
|
47
|
-
5001: "Could not obtain exclusive access on the configuration.",
|
48
|
-
5002: "Communication with the SHC failed.",
|
49
|
-
5003: "The owner did not accept the TaC latest version.",
|
50
|
-
5004: "One SHC already registered.",
|
51
|
-
5005: "The user has no SHC.",
|
52
|
-
5006: "Controller offline.",
|
53
|
-
5009: "Registration failure.",
|
54
|
-
# SmartCodes Errors
|
55
|
-
6000: "SmartCode request not allowed.",
|
56
|
-
6001: "The SmartCode cannot be redeemed.",
|
57
|
-
6002: "Restricted access.",
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
class LivisiException(Exception):
|
62
|
-
"""Base class for Livisi exceptions."""
|
63
|
-
|
64
|
-
def __init__(self, message: str = "", *args: object) -> None:
|
65
|
-
"""Initialize the exception with a message."""
|
66
|
-
self.message = message
|
67
|
-
super().__init__(message, *args)
|
68
|
-
|
69
|
-
|
70
|
-
class ShcUnreachableException(LivisiException):
|
71
|
-
"""Unable to connect to the Smart Home Controller."""
|
72
|
-
|
73
|
-
def __init__(
|
74
|
-
self,
|
75
|
-
message: str = "Unable to connect to the Smart Home Controller.",
|
76
|
-
*args: object,
|
77
|
-
) -> None:
|
78
|
-
"""Generate error with default message."""
|
79
|
-
super().__init__(message, *args)
|
80
|
-
|
81
|
-
|
82
|
-
class WrongCredentialException(LivisiException):
|
83
|
-
"""The user credentials were wrong."""
|
84
|
-
|
85
|
-
def __init__(
|
86
|
-
self, message: str = "The user credentials are wrong.", *args: object
|
87
|
-
) -> None:
|
88
|
-
"""Generate error with default message."""
|
89
|
-
super().__init__(message, *args)
|
90
|
-
|
91
|
-
|
92
|
-
class IncorrectIpAddressException(LivisiException):
|
93
|
-
"""The IP address provided by the user is incorrect."""
|
94
|
-
|
95
|
-
def __init__(
|
96
|
-
self,
|
97
|
-
message: str = "The IP address provided by the user is incorrect.",
|
98
|
-
*args: object,
|
99
|
-
) -> None:
|
100
|
-
"""Generate error with default message."""
|
101
|
-
super().__init__(message, *args)
|
102
|
-
|
103
|
-
|
104
|
-
class TokenExpiredException(LivisiException):
|
105
|
-
"""The authentication token is expired."""
|
106
|
-
|
107
|
-
def __init__(
|
108
|
-
self, message: str = "The authentication token is expired.", *args: object
|
109
|
-
) -> None:
|
110
|
-
"""Generate error with default message."""
|
111
|
-
super().__init__(message, *args)
|
112
|
-
|
113
|
-
|
114
|
-
class ErrorCodeException(LivisiException):
|
115
|
-
"""The request sent an errorcode (other than token expired) as response."""
|
116
|
-
|
117
|
-
def __init__(self, error_code: int, message: str = None, *args: object) -> None:
|
118
|
-
"""Generate error with code."""
|
119
|
-
self.error_code = error_code
|
120
|
-
if (message is None) and (error_code in ERROR_CODES):
|
121
|
-
message = ERROR_CODES[error_code]
|
122
|
-
elif message is None:
|
123
|
-
message = f"Unknown error code from shc: {error_code}"
|
124
|
-
super().__init__(message, *args)
|
livisi/livisi_json_util.py
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
"""Helper code to parse json to python dataclass (simple and non recursive)."""
|
2
|
-
from dataclasses import fields
|
3
|
-
import json
|
4
|
-
import re
|
5
|
-
|
6
|
-
|
7
|
-
def parse_dataclass(jsondata, clazz):
|
8
|
-
"""Convert keys to snake_case and parse to dataclass."""
|
9
|
-
|
10
|
-
if isinstance(jsondata, str | bytes | bytearray):
|
11
|
-
parsed_json = json.loads(jsondata)
|
12
|
-
elif isinstance(jsondata, dict):
|
13
|
-
parsed_json = jsondata
|
14
|
-
else:
|
15
|
-
parsed_json = {}
|
16
|
-
|
17
|
-
# Convert keys to snake_case
|
18
|
-
parsed_json = {
|
19
|
-
re.sub("([A-Z])", r"_\1", k).lower(): v for k, v in parsed_json.items()
|
20
|
-
}
|
21
|
-
# Only include keys that are fields in the dataclass
|
22
|
-
data_dict = {f.name: parsed_json.get(f.name) for f in fields(clazz)}
|
23
|
-
return clazz(**data_dict)
|
livisi/livisi_websocket.py
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
"""Code for communication with the Livisi application websocket."""
|
2
|
-
|
3
|
-
from collections.abc import Callable
|
4
|
-
import urllib.parse
|
5
|
-
|
6
|
-
from json import JSONDecodeError
|
7
|
-
import websockets.client
|
8
|
-
|
9
|
-
from .livisi_json_util import parse_dataclass
|
10
|
-
from .livisi_const import CLASSIC_WEBSOCKET_PORT, V2_WEBSOCKET_PORT, LOGGER
|
11
|
-
from .livisi_websocket_event import LivisiWebsocketEvent
|
12
|
-
|
13
|
-
|
14
|
-
class LivisiWebsocket:
|
15
|
-
"""Represents the websocket class."""
|
16
|
-
|
17
|
-
def __init__(self, aiolivisi) -> None:
|
18
|
-
"""Initialize the websocket."""
|
19
|
-
self.aiolivisi = aiolivisi
|
20
|
-
self.connection_url: str = None
|
21
|
-
self._websocket = None
|
22
|
-
self._disconnecting = False
|
23
|
-
|
24
|
-
def is_connected(self):
|
25
|
-
"""Return whether the webservice is currently connected."""
|
26
|
-
return self._websocket is not None
|
27
|
-
|
28
|
-
async def connect(self, on_data, on_close) -> None:
|
29
|
-
"""Connect to the socket."""
|
30
|
-
if self.aiolivisi.controller.is_v2:
|
31
|
-
port = V2_WEBSOCKET_PORT
|
32
|
-
token = urllib.parse.quote(self.aiolivisi.token)
|
33
|
-
else:
|
34
|
-
port = CLASSIC_WEBSOCKET_PORT
|
35
|
-
token = self.aiolivisi.token
|
36
|
-
ip_address = self.aiolivisi.host
|
37
|
-
self.connection_url = f"ws://{ip_address}:{port}/events?token={token}"
|
38
|
-
|
39
|
-
while not self._disconnecting:
|
40
|
-
try:
|
41
|
-
async with websockets.client.connect(
|
42
|
-
self.connection_url, ping_interval=10, ping_timeout=10
|
43
|
-
) as websocket:
|
44
|
-
LOGGER.info("WebSocket connection established.")
|
45
|
-
self._websocket = websocket
|
46
|
-
await self.consumer_handler(websocket, on_data)
|
47
|
-
except Exception as e:
|
48
|
-
LOGGER.exception("Error handling websocket connection", exc_info=e)
|
49
|
-
if not self._disconnecting:
|
50
|
-
LOGGER.warning("WebSocket disconnected unexpectedly, retrying...")
|
51
|
-
await on_close()
|
52
|
-
finally:
|
53
|
-
self._websocket = None
|
54
|
-
|
55
|
-
async def disconnect(self) -> None:
|
56
|
-
"""Close the websocket."""
|
57
|
-
self._disconnecting = True
|
58
|
-
if self._websocket is not None:
|
59
|
-
await self._websocket.close(code=1000, reason="Handle disconnect request")
|
60
|
-
LOGGER.info("WebSocket connection closed.")
|
61
|
-
self._websocket = None
|
62
|
-
self._disconnecting = False
|
63
|
-
|
64
|
-
async def consumer_handler(self, websocket, on_data: Callable):
|
65
|
-
"""Parse data transmitted via the websocket."""
|
66
|
-
try:
|
67
|
-
async for message in websocket:
|
68
|
-
LOGGER.debug("Received WebSocket message: %s", message)
|
69
|
-
|
70
|
-
try:
|
71
|
-
event_data = parse_dataclass(message, LivisiWebsocketEvent)
|
72
|
-
except JSONDecodeError:
|
73
|
-
LOGGER.warning("Cannot decode WebSocket message", exc_info=True)
|
74
|
-
continue
|
75
|
-
|
76
|
-
if event_data.properties is None or event_data.properties == {}:
|
77
|
-
LOGGER.warning("Received event with no properties, skipping.")
|
78
|
-
continue
|
79
|
-
|
80
|
-
# Remove the URL prefix and use just the ID (which is unique)
|
81
|
-
event_data.source = event_data.source.removeprefix("/device/")
|
82
|
-
event_data.source = event_data.source.removeprefix("/capability/")
|
83
|
-
|
84
|
-
on_data(event_data)
|
85
|
-
except Exception as e:
|
86
|
-
LOGGER.error("Unhandled error in WebSocket consumer handler", exc_info=e)
|
livisi/livisi_websocket_event.py
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
"""LivisiWebsocketEvent."""
|
2
|
-
from dataclasses import dataclass
|
3
|
-
|
4
|
-
|
5
|
-
@dataclass
|
6
|
-
class LivisiWebsocketEvent:
|
7
|
-
"""Encapuses a livisi event sent via the websocket."""
|
8
|
-
|
9
|
-
namespace: str
|
10
|
-
type: str | None
|
11
|
-
source: str
|
12
|
-
timestamp: str | None
|
13
|
-
properties: dict | None
|
livisi-0.0.1.dist-info/LICENSE
DELETED
File without changes
|
livisi-0.0.1.dist-info/METADATA
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: livisi
|
3
|
-
Version: 0.0.1
|
4
|
-
Summary: Connection library for the abandoned Livisi Smart Home system
|
5
|
-
Author-email: Felix Rotthowe <felix@planbnet.org>
|
6
|
-
Project-URL: Source, https://github.com/planbnet/livisi
|
7
|
-
Project-URL: Tracker, https://github.com/planbnet/livisi/issues
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Requires-Python: >=3.10
|
12
|
-
Description-Content-Type: text/markdown
|
13
|
-
License-File: LICENSE
|
14
|
-
Requires-Dist: colorlog==6.8.2
|
15
|
-
Requires-Dist: aiohttp>=3.8.5
|
16
|
-
Requires-Dist: websockets>=11.0.3
|
17
|
-
|
18
|
-
Livisi smart home connection library
|
19
|
-
|
20
|
-
Readme will be created when everything works as expected
|
livisi-0.0.1.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
livisi/__init__.py,sha256=Dh8B_PRVSmch_ClhFCVyV7O2doRCfREHvKGob6MYuRk,2225
|
2
|
-
livisi/livisi_connector.py,sha256=VagZFl46y49d3gqrr9iv0YSKLviHRLvAAxcMW4IO734,18095
|
3
|
-
livisi/livisi_const.py,sha256=6YqoPdlKX7ogfC_E_ea8opA0JeYIweXRRfpfu-QXTqc,779
|
4
|
-
livisi/livisi_controller.py,sha256=XyJ58XMXIxw5anIwHJ5MRVlNUBZyi3RjP8AO8HnYcXo,296
|
5
|
-
livisi/livisi_device.py,sha256=Qeh8kdVWY57S1aS5S4ATfi8t2a2k0Bx6njScRC0XKek,1230
|
6
|
-
livisi/livisi_errors.py,sha256=N-xEF42KfsCVUghdJYuM8yvpUiI_op1i1mpBiKcrM5Y,4511
|
7
|
-
livisi/livisi_json_util.py,sha256=6sQk8ycMUIAKL_8rD3dW_uHWRNa6QMcky-PvcEnM_88,735
|
8
|
-
livisi/livisi_websocket.py,sha256=KFY_n7w0grwnczjUDrdijK4RQi-8MOX81uLe6Nw-mSM,3465
|
9
|
-
livisi/livisi_websocket_event.py,sha256=pbjyiKid9gOWMcWiw5jq0dbo2DQ7dAQnxM0D_UJBltw,273
|
10
|
-
livisi-0.0.1.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
livisi-0.0.1.dist-info/METADATA,sha256=35qxzesQNHTTJmVs2eaTujj-LqP_0H96AmpcLwdiHqc,714
|
12
|
-
livisi-0.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
13
|
-
livisi-0.0.1.dist-info/top_level.txt,sha256=ctiU5MMpBSwoQR7mJWIuyB1ND1_g004Xa3vNmMsSiCs,7
|
14
|
-
livisi-0.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|