pytouchlinesl 0.1.0__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.
- pytouchlinesl/__init__.py +6 -0
- pytouchlinesl/client/__init__.py +4 -0
- pytouchlinesl/client/base.py +38 -0
- pytouchlinesl/client/client.py +196 -0
- pytouchlinesl/client/models/__init__.py +20 -0
- pytouchlinesl/client/models/models.py +173 -0
- pytouchlinesl/module.py +179 -0
- pytouchlinesl/touchlinesl.py +75 -0
- pytouchlinesl/zone.py +123 -0
- pytouchlinesl-0.1.0.dist-info/LICENSE +202 -0
- pytouchlinesl-0.1.0.dist-info/METADATA +129 -0
- pytouchlinesl-0.1.0.dist-info/RECORD +14 -0
- pytouchlinesl-0.1.0.dist-info/WHEEL +5 -0
- pytouchlinesl-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Provides an abstract API client implementation for clients working with the Roth API."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from pytouchlinesl.client.models.models import AccountModuleModel
|
|
6
|
+
|
|
7
|
+
from .models import ModuleModel
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseClient(ABC):
|
|
11
|
+
"""Base API client implementation for Roth API clients."""
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
async def authenticated(self) -> bool:
|
|
15
|
+
"""Report whether or not the client is authenticated with the API."""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
async def modules(self) -> list[AccountModuleModel]:
|
|
20
|
+
"""Return a list of TouchlineSL modules associated with the authenticated account."""
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
async def module(self, module_id: str) -> ModuleModel:
|
|
25
|
+
"""Return a specific module, by ID, that's associated with the authenticated account."""
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
async def set_zone_temperature(
|
|
30
|
+
self, module_id: str, mode_id: int, zone_id: int, temperature: float
|
|
31
|
+
):
|
|
32
|
+
"""Set a constant target temperature for a specific zone, in a specific module."""
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
async def set_zone_schedule(self, module_id: str, zone_id: int, schedule_id: int):
|
|
37
|
+
"""Assign a specific zone to a specific global schedule in the module's configuration."""
|
|
38
|
+
pass
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"""An API client for the public Roth TouchlineSL API.
|
|
2
|
+
|
|
3
|
+
API Documentation: https://api-documentation.roth-touchlinesl.com/
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import aiohttp
|
|
11
|
+
|
|
12
|
+
from pytouchlinesl.client.models import GlobalScheduleModel
|
|
13
|
+
|
|
14
|
+
from .base import BaseClient
|
|
15
|
+
from .models import AccountModuleModel, ModuleModel
|
|
16
|
+
|
|
17
|
+
API_URL = "https://roth-touchlinesl.com/api/v1"
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RothAPIError(Exception):
|
|
23
|
+
"""An exception raised when an unsuccessful request is made to the Roth API."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, status: int, data: Any = None):
|
|
26
|
+
"""Construct an instance of the exception."""
|
|
27
|
+
super().__init__()
|
|
28
|
+
self._status = status
|
|
29
|
+
self._data = data
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def status(self) -> int:
|
|
33
|
+
"""Return the HTTP status code of the failed request."""
|
|
34
|
+
return self._status
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def data(self) -> Any:
|
|
38
|
+
"""Return any data included in the response of the failed request."""
|
|
39
|
+
return self._data
|
|
40
|
+
|
|
41
|
+
def __repr__(self) -> str: # noqa: D105
|
|
42
|
+
return f"{self.__class__.__name__}({self.__str__()})"
|
|
43
|
+
|
|
44
|
+
def __str__(self) -> str: # noqa: D105
|
|
45
|
+
msg = f"{self.status}"
|
|
46
|
+
|
|
47
|
+
if self.data is not None:
|
|
48
|
+
msg += " " + json.dumps(self.data)
|
|
49
|
+
|
|
50
|
+
return msg
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class RothAPI(BaseClient):
|
|
54
|
+
"""An implementation of the BaseClient which interacts with Roth's public API."""
|
|
55
|
+
|
|
56
|
+
def __init__(self, username, password):
|
|
57
|
+
"""Construct an instance of the client.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
username: Roth TouchlineSL account email.
|
|
61
|
+
password: Roth TouchlineSL account password.
|
|
62
|
+
"""
|
|
63
|
+
self._username = username
|
|
64
|
+
self._password = password
|
|
65
|
+
self._user_id = None
|
|
66
|
+
self._token = None
|
|
67
|
+
|
|
68
|
+
async def _login(self):
|
|
69
|
+
"""Login to the Roth API, and store the received bearer token and user id."""
|
|
70
|
+
data = {"username": self._username, "password": self._password}
|
|
71
|
+
resp = await self._post("/authentication", json=data)
|
|
72
|
+
|
|
73
|
+
self._user_id = resp.get("user_id")
|
|
74
|
+
self._token = resp.get("token")
|
|
75
|
+
|
|
76
|
+
async def authenticated(self) -> bool:
|
|
77
|
+
"""Report whether or not the client is authenticated with the API."""
|
|
78
|
+
if self._token is None:
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
resp = await self._authed_get("/authentication")
|
|
82
|
+
return resp.get("authenticated", False)
|
|
83
|
+
|
|
84
|
+
async def modules(self) -> list[AccountModuleModel]:
|
|
85
|
+
"""Return a list of TouchlineSL modules associated with the authenticated account."""
|
|
86
|
+
if self._token is None:
|
|
87
|
+
await self._login()
|
|
88
|
+
|
|
89
|
+
resp = await self._authed_get(f"/users/{self._user_id}/modules")
|
|
90
|
+
return [AccountModuleModel(**m) for m in resp]
|
|
91
|
+
|
|
92
|
+
async def module(self, module_id: str) -> ModuleModel:
|
|
93
|
+
"""Return a specific module, by ID, that's associated with the authenticated account."""
|
|
94
|
+
if self._token is None:
|
|
95
|
+
await self._login()
|
|
96
|
+
|
|
97
|
+
resp = await self._authed_get(f"/users/{self._user_id}/modules/{module_id}")
|
|
98
|
+
return ModuleModel(**resp)
|
|
99
|
+
|
|
100
|
+
async def set_zone_temperature(
|
|
101
|
+
self, module_id: str, mode_id: int, zone_id: int, temperature: float
|
|
102
|
+
):
|
|
103
|
+
"""Set a constant target temperature for a specific zone, in a specific module."""
|
|
104
|
+
data = {
|
|
105
|
+
"mode": {
|
|
106
|
+
"id": mode_id,
|
|
107
|
+
"parentId": zone_id,
|
|
108
|
+
"mode": "constantTemp",
|
|
109
|
+
"constTempTime": 0,
|
|
110
|
+
"setTemperature": int(temperature * 10),
|
|
111
|
+
"scheduleIndex": 0,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await self._authd_post(url=f"/users/{self._user_id}/modules/{module_id}/zones", data=data)
|
|
116
|
+
|
|
117
|
+
async def set_zone_schedule(self, module_id: str, zone_id: int, schedule_id: int):
|
|
118
|
+
"""Assign a specific zone to a specific global schedule in the module's configuration."""
|
|
119
|
+
module: ModuleModel = await self.module(module_id=module_id)
|
|
120
|
+
schedules = module.zones.global_schedules.elements
|
|
121
|
+
schedule = next((s for s in schedules if s.id == schedule_id), None)
|
|
122
|
+
assert isinstance(schedule, GlobalScheduleModel)
|
|
123
|
+
|
|
124
|
+
# Get a list of zones which are already assigned to the schedule.
|
|
125
|
+
# The Roth API is relatively limited, and adding a zone to a schedule means
|
|
126
|
+
# completely re-specifying the schedule, including intervals and assigned zones.
|
|
127
|
+
zones_on_schedule = [
|
|
128
|
+
z
|
|
129
|
+
for z in module.zones.elements
|
|
130
|
+
if (z.mode.mode == "globalSchedule" and z.mode.schedule_index == schedule.index)
|
|
131
|
+
or z.zone.id == zone_id
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
# TODO: This be simplified with Pydantic models
|
|
135
|
+
data = {
|
|
136
|
+
"scheduleName": schedule.name,
|
|
137
|
+
"setInZones": [{"zoneId": z.zone.id, "modeId": z.mode.id} for z in zones_on_schedule],
|
|
138
|
+
"schedule": {
|
|
139
|
+
"id": schedule.id,
|
|
140
|
+
"index": schedule.index,
|
|
141
|
+
"p0Days": schedule.p0_days,
|
|
142
|
+
"p0SetbackTemp": schedule.p0_setback_temp,
|
|
143
|
+
# Empty intervals start/end with a value of 6100, which is invalid
|
|
144
|
+
# if sent in this request.
|
|
145
|
+
"p0Intervals": [
|
|
146
|
+
i.model_dump(by_alias=True) for i in schedule.p0_intervals if i.start != 6100
|
|
147
|
+
],
|
|
148
|
+
"p1Days": schedule.p1_days,
|
|
149
|
+
"p1SetbackTemp": schedule.p1_setback_temp,
|
|
150
|
+
"p1Intervals": [
|
|
151
|
+
i.model_dump(by_alias=True) for i in schedule.p1_intervals if i.start != 6100
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
await self._authd_post(
|
|
157
|
+
url=f"/users/{self._user_id}/modules/{module_id}/zones/{zone_id}/global_schedule",
|
|
158
|
+
data=data,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
async def _authed_get(self, url: str, headers: dict[str, str] = {}) -> dict:
|
|
162
|
+
"""Perform an authenticated GET request to the Roth TouchlineSL API."""
|
|
163
|
+
headers.update({"authorization": f"Bearer {self._token}"})
|
|
164
|
+
return await self._get(url, headers)
|
|
165
|
+
|
|
166
|
+
async def _get(self, url: str, headers: dict[str, str] = {}) -> dict:
|
|
167
|
+
"""Perform a GET request to the Roth TouchlineSL API."""
|
|
168
|
+
logger.debug("GET %s%s", API_URL, url)
|
|
169
|
+
|
|
170
|
+
async with aiohttp.ClientSession() as session:
|
|
171
|
+
req = await session.get(f"{API_URL}{url}", headers=headers)
|
|
172
|
+
resp = await req.json()
|
|
173
|
+
|
|
174
|
+
if not req.ok:
|
|
175
|
+
raise RothAPIError(status=req.status, data=resp)
|
|
176
|
+
|
|
177
|
+
return resp
|
|
178
|
+
|
|
179
|
+
async def _authd_post(self, url: str, headers: dict[str, str] = {}, data: dict = {}) -> dict:
|
|
180
|
+
"""Perform an authenticated POST request to the Roth TouchlineSL API."""
|
|
181
|
+
headers.update({"authorization": f"Bearer {self._token}"})
|
|
182
|
+
return await self._post(url, headers, data)
|
|
183
|
+
|
|
184
|
+
async def _post(self, url: str, headers: dict[str, str] = {}, json: dict = {}) -> dict:
|
|
185
|
+
"""Perform a POST request to the Roth TouchlineSL API."""
|
|
186
|
+
logger.debug("POST %s%s", API_URL, url)
|
|
187
|
+
|
|
188
|
+
async with aiohttp.ClientSession() as session:
|
|
189
|
+
req = await session.post(f"{API_URL}{url}", headers=headers, json=json)
|
|
190
|
+
|
|
191
|
+
resp = await req.json()
|
|
192
|
+
|
|
193
|
+
if not req.ok:
|
|
194
|
+
raise RothAPIError(status=req.status, data=resp)
|
|
195
|
+
|
|
196
|
+
return resp
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Provides Pydantic models representing responses from the Roth TouchlineSL API."""
|
|
2
|
+
|
|
3
|
+
from .models import (
|
|
4
|
+
AccountModuleModel,
|
|
5
|
+
ControllerModeModel,
|
|
6
|
+
ControllerParametersModel,
|
|
7
|
+
GlobalScheduleModel,
|
|
8
|
+
GlobalSchedulesModel,
|
|
9
|
+
LocalScheduleModel,
|
|
10
|
+
ModuleModel,
|
|
11
|
+
ParamsModel,
|
|
12
|
+
ScheduleIntervalModel,
|
|
13
|
+
TileModel,
|
|
14
|
+
ZoneAttributesModel,
|
|
15
|
+
ZoneDescriptionModel,
|
|
16
|
+
ZoneFlagsModel,
|
|
17
|
+
ZoneModel,
|
|
18
|
+
ZoneModeModel,
|
|
19
|
+
ZonesModel,
|
|
20
|
+
)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Provides models that represent the data structures returned by the Roth API.
|
|
2
|
+
|
|
3
|
+
These are mostly auto-generated using responses received from the API, with some
|
|
4
|
+
tweaks to types and names.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ZoneFlagsModel(BaseModel):
|
|
13
|
+
relay_state: str = Field(..., alias="relayState")
|
|
14
|
+
min_one_window_open: bool = Field(..., alias="minOneWindowOpen")
|
|
15
|
+
algorithm: str
|
|
16
|
+
floor_sensor: int = Field(..., alias="floorSensor")
|
|
17
|
+
humidity_algorytm: int = Field(..., alias="humidityAlgorytm")
|
|
18
|
+
zone_excluded: int = Field(..., alias="zoneExcluded")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ZoneAttributesModel(BaseModel):
|
|
22
|
+
id: int
|
|
23
|
+
parent_id: int = Field(..., alias="parentId")
|
|
24
|
+
time: str
|
|
25
|
+
during_change: bool = Field(..., alias="duringChange")
|
|
26
|
+
index: int
|
|
27
|
+
current_temperature: Optional[int] = Field(..., alias="currentTemperature")
|
|
28
|
+
set_temperature: int = Field(..., alias="setTemperature")
|
|
29
|
+
flags: ZoneFlagsModel
|
|
30
|
+
zone_state: Literal["zoneOff", "noAlarm"] = Field(..., alias="zoneState")
|
|
31
|
+
signal_strength: Optional[int] = Field(..., alias="signalStrength")
|
|
32
|
+
battery_level: Optional[int] = Field(..., alias="batteryLevel")
|
|
33
|
+
actuators_open: int = Field(..., alias="actuatorsOpen")
|
|
34
|
+
humidity: int
|
|
35
|
+
visibility: bool
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ZoneDescriptionModel(BaseModel):
|
|
39
|
+
id: int
|
|
40
|
+
parent_id: int = Field(..., alias="parentId")
|
|
41
|
+
name: str
|
|
42
|
+
style_id: int = Field(..., alias="styleId")
|
|
43
|
+
style_icon: str = Field(..., alias="styleIcon")
|
|
44
|
+
during_change: bool = Field(..., alias="duringChange")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ZoneModeModel(BaseModel):
|
|
48
|
+
id: int
|
|
49
|
+
parent_id: int = Field(..., alias="parentId")
|
|
50
|
+
mode: Literal["constantTemp", "globalSchedule", "localSchedule", "timeLimit"]
|
|
51
|
+
const_temp_time: int = Field(..., alias="constTempTime")
|
|
52
|
+
set_temperature: int = Field(..., alias="setTemperature")
|
|
53
|
+
schedule_index: int = Field(..., alias="scheduleIndex")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ScheduleIntervalModel(BaseModel):
|
|
57
|
+
start: int
|
|
58
|
+
stop: int
|
|
59
|
+
temp: int
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class LocalScheduleModel(BaseModel):
|
|
63
|
+
id: int
|
|
64
|
+
parent_id: int = Field(..., alias="parentId")
|
|
65
|
+
index: int
|
|
66
|
+
p0_days: List[str] = Field(..., alias="p0Days")
|
|
67
|
+
p0_intervals: List[ScheduleIntervalModel] = Field(..., alias="p0Intervals")
|
|
68
|
+
p0_setback_temp: int = Field(..., alias="p0SetbackTemp")
|
|
69
|
+
p1_days: List[str] = Field(..., alias="p1Days")
|
|
70
|
+
p1_intervals: List[ScheduleIntervalModel] = Field(..., alias="p1Intervals")
|
|
71
|
+
p1_setback_temp: int = Field(..., alias="p1SetbackTemp")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ZoneModel(BaseModel):
|
|
75
|
+
zone: ZoneAttributesModel
|
|
76
|
+
description: ZoneDescriptionModel
|
|
77
|
+
mode: ZoneModeModel
|
|
78
|
+
schedule: LocalScheduleModel
|
|
79
|
+
actuators: List
|
|
80
|
+
underfloor: Dict[str, Any]
|
|
81
|
+
windows_sensors: List = Field(..., alias="windowsSensors")
|
|
82
|
+
additional_contacts: List = Field(..., alias="additionalContacts")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class GlobalScheduleModel(BaseModel):
|
|
86
|
+
id: int
|
|
87
|
+
parent_id: int = Field(..., alias="parentId")
|
|
88
|
+
index: int
|
|
89
|
+
name: str
|
|
90
|
+
p0_days: List[str] = Field(..., alias="p0Days")
|
|
91
|
+
p0_setback_temp: int = Field(..., alias="p0SetbackTemp")
|
|
92
|
+
p0_intervals: List[ScheduleIntervalModel] = Field(..., alias="p0Intervals")
|
|
93
|
+
p1_days: List[str] = Field(..., alias="p1Days")
|
|
94
|
+
p1_setback_temp: int = Field(..., alias="p1SetbackTemp")
|
|
95
|
+
p1_intervals: List[ScheduleIntervalModel] = Field(..., alias="p1Intervals")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class GlobalSchedulesModel(BaseModel):
|
|
99
|
+
time: str
|
|
100
|
+
during_change: bool = Field(..., alias="duringChange")
|
|
101
|
+
elements: List[GlobalScheduleModel]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ControllerModeModel(BaseModel):
|
|
105
|
+
id: int
|
|
106
|
+
parent_id: int = Field(..., alias="parentId")
|
|
107
|
+
type: int
|
|
108
|
+
txt_id: int = Field(..., alias="txtId")
|
|
109
|
+
icon_id: int = Field(..., alias="iconId")
|
|
110
|
+
value: int
|
|
111
|
+
menu_id: int = Field(..., alias="menuId")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class ControllerParametersModel(BaseModel):
|
|
115
|
+
controller_mode: ControllerModeModel = Field(..., alias="controllerMode")
|
|
116
|
+
global_schedules_number: Dict[str, Any] = Field(..., alias="globalSchedulesNumber")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class ZonesModel(BaseModel):
|
|
120
|
+
transaction_time: str
|
|
121
|
+
elements: List[ZoneModel]
|
|
122
|
+
global_schedules: GlobalSchedulesModel = Field(..., alias="globalSchedules")
|
|
123
|
+
controller_parameters: ControllerParametersModel = Field(..., alias="controllerParameters")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class ParamsModel(BaseModel):
|
|
127
|
+
description: str
|
|
128
|
+
working_status: Optional[bool] = Field(None, alias="workingStatus")
|
|
129
|
+
txt_id: int = Field(..., alias="txtId")
|
|
130
|
+
icon_id: int = Field(..., alias="iconId")
|
|
131
|
+
version: Optional[str] = None
|
|
132
|
+
company_id: Optional[int] = Field(None, alias="companyId")
|
|
133
|
+
controller_name: Optional[str] = Field(None, alias="controllerName")
|
|
134
|
+
main_controller_id: Optional[int] = Field(None, alias="mainControllerId")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class TileModel(BaseModel):
|
|
138
|
+
id: int
|
|
139
|
+
parent_id: int = Field(..., alias="parentId")
|
|
140
|
+
type: int
|
|
141
|
+
menu_id: int = Field(..., alias="menuId")
|
|
142
|
+
order_id: Any = Field(..., alias="orderId")
|
|
143
|
+
visibility: bool
|
|
144
|
+
params: ParamsModel
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class ModuleModel(BaseModel):
|
|
148
|
+
zones: ZonesModel
|
|
149
|
+
tiles: List[TileModel]
|
|
150
|
+
tiles_order: Any = Field(..., alias="tilesOrder")
|
|
151
|
+
tiles_last_update: str = Field(..., alias="tilesLastUpdate")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class AccountModuleModel(BaseModel):
|
|
155
|
+
id: int
|
|
156
|
+
default: bool
|
|
157
|
+
name: str
|
|
158
|
+
email: str
|
|
159
|
+
type: str
|
|
160
|
+
controller_status: str = Field(..., alias="controllerStatus")
|
|
161
|
+
module_status: str = Field(..., alias="moduleStatus")
|
|
162
|
+
additional_information: str = Field(..., alias="additionalInformation")
|
|
163
|
+
phone_number: Any = Field(..., alias="phoneNumber")
|
|
164
|
+
zip_code: str = Field(..., alias="zipCode")
|
|
165
|
+
tag: str
|
|
166
|
+
country: str
|
|
167
|
+
gmt_id: int = Field(..., alias="gmtId")
|
|
168
|
+
gmt_time: str = Field(..., alias="gmtTime")
|
|
169
|
+
postcode_policy_accepted: bool = Field(..., alias="postcodePolicyAccepted")
|
|
170
|
+
style: str
|
|
171
|
+
version: str
|
|
172
|
+
company: str
|
|
173
|
+
udid: str
|
pytouchlinesl/module.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""Provides a representation of a single Roth TouchlineSL module.
|
|
2
|
+
|
|
3
|
+
In reality, this usually represents the underfloor heating for
|
|
4
|
+
a specific building. It masks the upstream Roth API, which provides
|
|
5
|
+
relatively few methods for fetching details about particular zones
|
|
6
|
+
and schedules by providing methods to query them directly.
|
|
7
|
+
|
|
8
|
+
Because of the upstream API design, there is an inbuilt caching
|
|
9
|
+
mechanism that's used to prevent making too many calls to the
|
|
10
|
+
modules endpoint. The cache can be invalidated to ensure that
|
|
11
|
+
new data is fetched using the `invalidate_cache` method.
|
|
12
|
+
|
|
13
|
+
Typical usage:
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
from pytouchlinesl import TouchlineSL
|
|
17
|
+
|
|
18
|
+
tsl = TouchlineSL(username"foo@bar.com", password="deadbeef")
|
|
19
|
+
|
|
20
|
+
modules = await tsl.modules()
|
|
21
|
+
if modules:
|
|
22
|
+
module = modules[0]
|
|
23
|
+
zone = await module.zone_by_name("Kitchen")
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import time
|
|
27
|
+
|
|
28
|
+
from pytouchlinesl.client import BaseClient
|
|
29
|
+
from pytouchlinesl.client.models import GlobalScheduleModel, ModuleModel
|
|
30
|
+
from pytouchlinesl.client.models.models import AccountModuleModel
|
|
31
|
+
from pytouchlinesl.zone import Zone
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Module:
|
|
35
|
+
"""A representation of a single Roth TouchlineSL module."""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
client: BaseClient,
|
|
41
|
+
module_data: AccountModuleModel,
|
|
42
|
+
cache_validity: int = 30,
|
|
43
|
+
):
|
|
44
|
+
"""Construct an instance of a module.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
client: The underlying API client to use for fetching data.
|
|
48
|
+
module_data: A raw representation of the Module returned from a client instance.
|
|
49
|
+
cache_validity: (Optional) The number of seconds for which module data should be cached.
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
self._client: BaseClient = client
|
|
53
|
+
|
|
54
|
+
# Information about the module itself
|
|
55
|
+
self.id = module_data.udid
|
|
56
|
+
self.name = module_data.name
|
|
57
|
+
self.email = module_data.email
|
|
58
|
+
self.type = module_data.type
|
|
59
|
+
self.version = module_data.version
|
|
60
|
+
|
|
61
|
+
# Raw data about the zones, schedules, tiles in the module
|
|
62
|
+
self._raw_data: ModuleModel
|
|
63
|
+
# Unix timestamp representing the last time the _raw_data was fetched
|
|
64
|
+
self._last_fetched = 0
|
|
65
|
+
self._cache_validity = cache_validity
|
|
66
|
+
|
|
67
|
+
self._zones: list[Zone] = []
|
|
68
|
+
self._schedules: list[GlobalScheduleModel] = []
|
|
69
|
+
|
|
70
|
+
async def _data(self, *, refresh: bool = False) -> ModuleModel:
|
|
71
|
+
"""Get the raw representation of the module from the upstream API.
|
|
72
|
+
|
|
73
|
+
If the data has never been fetched from upstream, or the data is older
|
|
74
|
+
than the cache validity period, then the data is refreshed using the
|
|
75
|
+
upstream API.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
refresh: (Optional): Force the data to be refreshed using the API.
|
|
79
|
+
"""
|
|
80
|
+
if refresh or (round(time.time() * 1000) - self._last_fetched) > self._cache_validity:
|
|
81
|
+
self._raw_data = await self._client.module(self.id)
|
|
82
|
+
self._last_fetched = round(time.time() * 1000)
|
|
83
|
+
|
|
84
|
+
return self._raw_data
|
|
85
|
+
|
|
86
|
+
def invalidate_cache(self):
|
|
87
|
+
"""Reset the cache, ensuring new data is fetched the next time its accessed."""
|
|
88
|
+
self._last_fetched = 0
|
|
89
|
+
self._zones = []
|
|
90
|
+
self._schedules = []
|
|
91
|
+
|
|
92
|
+
async def zones(self, *, include_off: bool = False, refresh: bool = False) -> list[Zone]:
|
|
93
|
+
"""Return a list of zones, optionally including those which are disabled.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
include_off: (Optional) Include zones which are switched off in the results.
|
|
97
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
98
|
+
"""
|
|
99
|
+
if not self._zones or refresh:
|
|
100
|
+
data = await self._data(refresh=refresh)
|
|
101
|
+
|
|
102
|
+
for z in data.zones.elements:
|
|
103
|
+
schedule = await self.schedule_by_idx(z.mode.schedule_index)
|
|
104
|
+
zone = Zone(module=self, client=self._client, zone_data=z, schedule=schedule)
|
|
105
|
+
self._zones.append(zone)
|
|
106
|
+
|
|
107
|
+
if include_off:
|
|
108
|
+
return self._zones
|
|
109
|
+
|
|
110
|
+
return [z for z in self._zones if z.enabled]
|
|
111
|
+
|
|
112
|
+
async def zone(self, zone_id: int, *, refresh: bool = False) -> Zone | None:
|
|
113
|
+
"""Return a specific zone, by ID.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
zone_id: The ID of the desired zone.
|
|
117
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
118
|
+
"""
|
|
119
|
+
zones = await self.zones(include_off=True, refresh=refresh)
|
|
120
|
+
return next((z for z in zones if z.id == zone_id), None)
|
|
121
|
+
|
|
122
|
+
async def zone_by_name(self, zone_name: str, *, refresh: bool = False) -> Zone | None:
|
|
123
|
+
"""Return a specific zone, by name.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
zone_name: The name of the desired zone.
|
|
127
|
+
include_off: (Optional) Include zones which are switched off in the results.
|
|
128
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
129
|
+
"""
|
|
130
|
+
zones = await self.zones(include_off=True, refresh=refresh)
|
|
131
|
+
return next((z for z in zones if z.name == zone_name), None)
|
|
132
|
+
|
|
133
|
+
async def schedules(self, *, refresh: bool = False) -> list[GlobalScheduleModel]:
|
|
134
|
+
"""Return a list of the module's global schedules.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
138
|
+
"""
|
|
139
|
+
if not self._schedules or refresh:
|
|
140
|
+
data = await self._data(refresh=refresh)
|
|
141
|
+
self._schedules = data.zones.global_schedules.elements
|
|
142
|
+
|
|
143
|
+
return self._schedules
|
|
144
|
+
|
|
145
|
+
async def schedule(
|
|
146
|
+
self, schedule_id: int, *, refresh: bool = False
|
|
147
|
+
) -> GlobalScheduleModel | None:
|
|
148
|
+
"""Return a specific global schedule, by ID.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
schedule_id: The ID of the desired schedule.
|
|
152
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
153
|
+
"""
|
|
154
|
+
schedules = await self.schedules(refresh=refresh)
|
|
155
|
+
return next((s for s in schedules if s.id == schedule_id), None)
|
|
156
|
+
|
|
157
|
+
async def schedule_by_idx(
|
|
158
|
+
self, schedule_idx: int, *, refresh: bool = False
|
|
159
|
+
) -> GlobalScheduleModel | None:
|
|
160
|
+
"""Return a specific global schedule, by index.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
schedule_idx: The index of the desired schedule.
|
|
164
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
165
|
+
"""
|
|
166
|
+
schedules = await self.schedules(refresh=refresh)
|
|
167
|
+
return next((s for s in schedules if s.index == schedule_idx), None)
|
|
168
|
+
|
|
169
|
+
async def schedule_by_name(
|
|
170
|
+
self, schedule_name: str, *, refresh: bool = False
|
|
171
|
+
) -> GlobalScheduleModel | None:
|
|
172
|
+
"""Return a specific global schedule, by name.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
schedule_name: The name of the desired schedule.
|
|
176
|
+
refresh: (Optional) Force the data to be refreshed using the API.
|
|
177
|
+
"""
|
|
178
|
+
schedules = await self.schedules(refresh=refresh)
|
|
179
|
+
return next((s for s in schedules if s.name == schedule_name), None)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Provides an API client for a specific Roth TouchlineSL account.
|
|
2
|
+
|
|
3
|
+
This is the top-level construct expected to be used for interacting
|
|
4
|
+
with the TouchlineSL API. It provides a way to list the heating
|
|
5
|
+
modules associated with a given account, the authentication details
|
|
6
|
+
for which are provided by a RothAPI instance.
|
|
7
|
+
|
|
8
|
+
Typical usage example:
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from pytouchlinesl import TouchlineSL
|
|
12
|
+
|
|
13
|
+
tsl = TouchlineSL(username"foo@bar.com", password="deadbeef")
|
|
14
|
+
modules = await tsl.modules()
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
|
|
19
|
+
from pytouchlinesl.client import BaseClient, RothAPI
|
|
20
|
+
from pytouchlinesl.module import Module
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TouchlineSL:
|
|
26
|
+
"""An API client for a specific Roth TouchlineSL account."""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
username: str | None = None,
|
|
32
|
+
password: str | None = None,
|
|
33
|
+
client: BaseClient | None = None,
|
|
34
|
+
):
|
|
35
|
+
"""Construct the instance with either credentials or an authenticated client.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
username: (Optional) Username for TouchlineSL account. Ignored if client is passed.
|
|
39
|
+
password: (Optional) Password for TouchlineSL account. Ignored if client is passed.
|
|
40
|
+
client: (Optional) An instance of a RothAPI class.
|
|
41
|
+
"""
|
|
42
|
+
self._modules: list[Module] = []
|
|
43
|
+
|
|
44
|
+
if client:
|
|
45
|
+
if username or password:
|
|
46
|
+
logger.warning(
|
|
47
|
+
"username and password arguments will be ignored because a client was passed"
|
|
48
|
+
)
|
|
49
|
+
self._client = client
|
|
50
|
+
else:
|
|
51
|
+
if username is None or password is None:
|
|
52
|
+
raise TypeError("username and password must be strings if no client is provided")
|
|
53
|
+
self._client = RothAPI(username=username, password=password)
|
|
54
|
+
|
|
55
|
+
async def modules(self, *, refresh: bool = False) -> list[Module]:
|
|
56
|
+
"""Report a list of Roth TouchlineSL modules associated with the account.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
refresh: Force the API client to refresh cached module data
|
|
60
|
+
"""
|
|
61
|
+
if not self._modules or refresh:
|
|
62
|
+
data = await self._client.modules()
|
|
63
|
+
self._modules = [Module(client=self._client, module_data=m) for m in data]
|
|
64
|
+
|
|
65
|
+
return self._modules
|
|
66
|
+
|
|
67
|
+
async def module(self, *, module_id: str, refresh: bool = False) -> Module | None:
|
|
68
|
+
"""Fetch a specific module, by module ID.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
module_id: The unique identifier of the TouchlineSL module to fetch
|
|
72
|
+
refresh: Force the API client to refresh cached module data
|
|
73
|
+
"""
|
|
74
|
+
modules = await self.modules(refresh=refresh)
|
|
75
|
+
return next((m for m in modules if m.id == module_id), None)
|
pytouchlinesl/zone.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""A representation of a single Roth TouchlineSL zone.
|
|
2
|
+
|
|
3
|
+
In most cases, a Zone represents a specific room in a building.
|
|
4
|
+
Zones can report on both temperature and humidity.
|
|
5
|
+
|
|
6
|
+
Each zone can either be set with a constant target temperature,
|
|
7
|
+
set to a specific global schedule, or set onto a local schedule.
|
|
8
|
+
|
|
9
|
+
Typical Usage:
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
from pytouchlinesl import TouchlineSL
|
|
13
|
+
|
|
14
|
+
tsl = TouchlineSL(username"foo@bar.com", password="deadbeef")
|
|
15
|
+
|
|
16
|
+
# Get the module from the account
|
|
17
|
+
module = await tsl.modules()
|
|
18
|
+
module = modules[0]
|
|
19
|
+
|
|
20
|
+
# Get a specific zone from the module
|
|
21
|
+
zone = await module.zone_by_name("Kitchen")
|
|
22
|
+
temp = zone.temperature
|
|
23
|
+
|
|
24
|
+
# Set the zone to a constant target temp of 22.5
|
|
25
|
+
await zone.set_temperature(22.5)
|
|
26
|
+
|
|
27
|
+
# Set the zone onto a specific global schedule
|
|
28
|
+
schedule = module.schedule_by_name("Living Spaces")
|
|
29
|
+
await zone.set_schedule(schedule.id)
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from typing import TYPE_CHECKING, Literal
|
|
33
|
+
|
|
34
|
+
from .client import BaseClient
|
|
35
|
+
from .client.models import GlobalScheduleModel, LocalScheduleModel, ZoneModel
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
from .module import Module
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Zone:
|
|
42
|
+
"""A representation of a single Roth TouchlineSL zone."""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
module: "Module",
|
|
47
|
+
client: BaseClient,
|
|
48
|
+
zone_data: ZoneModel,
|
|
49
|
+
schedule: GlobalScheduleModel | LocalScheduleModel | None,
|
|
50
|
+
):
|
|
51
|
+
"""Construct an instance of a zone.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
module: The Module this Zone belongs to.
|
|
55
|
+
client: The underlying API client to use for fetching data.
|
|
56
|
+
zone_data: A raw representation of the Zone returned from a client instance.
|
|
57
|
+
schedule: None if Zone is set to constant temp, otherwise instance of the global
|
|
58
|
+
schedule assigned to the zone
|
|
59
|
+
"""
|
|
60
|
+
self._module = module
|
|
61
|
+
self._client = client
|
|
62
|
+
self._raw_data = zone_data
|
|
63
|
+
self._schedule = schedule
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def name(self) -> str:
|
|
67
|
+
"""Return the configured name of the zone."""
|
|
68
|
+
return self._raw_data.description.name
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def id(self) -> int:
|
|
72
|
+
"""Return the ID of the zone."""
|
|
73
|
+
return self._raw_data.zone.id
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def temperature(self) -> float | None:
|
|
77
|
+
"""Return the current temperature of the zone, if it's enabled, otherwise None."""
|
|
78
|
+
if self._raw_data.zone.current_temperature:
|
|
79
|
+
return float(int(self._raw_data.zone.current_temperature) / 10)
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def target_temperature(self) -> float:
|
|
84
|
+
"""Return the target temperature of the zone."""
|
|
85
|
+
return float(int(self._raw_data.zone.set_temperature) / 10)
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def humidity(self) -> float:
|
|
89
|
+
"""Return the humidity of the zone."""
|
|
90
|
+
return float(int(self._raw_data.zone.humidity))
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def mode(self) -> Literal["constantTemp", "globalSchedule", "localSchedule", "timeLimit"]:
|
|
94
|
+
"""Return the mode of the zone."""
|
|
95
|
+
return self._raw_data.mode.mode
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def enabled(self) -> bool:
|
|
99
|
+
"""Return whether or not the zone is enabled."""
|
|
100
|
+
return self._raw_data.zone.zone_state != "zoneOff"
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def schedule(self) -> GlobalScheduleModel | LocalScheduleModel | None:
|
|
104
|
+
"""Return the zone's current schedule. If a constant temp is set, returns None."""
|
|
105
|
+
if self.mode == "constantTemp":
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
return self._schedule
|
|
109
|
+
|
|
110
|
+
async def set_temperature(self, temperature: float):
|
|
111
|
+
"""Set a constant target temperature for the zone."""
|
|
112
|
+
await self._client.set_zone_temperature(
|
|
113
|
+
module_id=self._module.id,
|
|
114
|
+
zone_id=self.id,
|
|
115
|
+
mode_id=self._raw_data.mode.id,
|
|
116
|
+
temperature=temperature,
|
|
117
|
+
)
|
|
118
|
+
self._module.invalidate_cache()
|
|
119
|
+
|
|
120
|
+
async def set_schedule(self, schedule_id: int):
|
|
121
|
+
"""Assign the zone to a specific global schedule."""
|
|
122
|
+
await self._client.set_zone_schedule(self._module.id, self.id, schedule_id)
|
|
123
|
+
self._module.invalidate_cache()
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright jnsgruk
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pytouchlinesl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An API client for Roth's TouchlineSL control system.
|
|
5
|
+
Author-email: Jon Seager <jon@sgrs.uk>
|
|
6
|
+
Project-URL: Homepage, https://github.com/jnsgruk/pytouchlinesl
|
|
7
|
+
Project-URL: Issues, https://github.com/jnsgruk/pytouchlinesl/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software 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: aiohttp
|
|
15
|
+
Requires-Dist: pydantic >=2.8.2
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-asyncio ; extra == 'dev'
|
|
19
|
+
Requires-Dist: ruff ; extra == 'dev'
|
|
20
|
+
|
|
21
|
+
# A Python Library for Roth's TouchlineSL System
|
|
22
|
+
|
|
23
|
+
<a href="https://github.com/jnsgruk/pytouchlinesl/actions/workflows/test.yaml"><img src="https://github.com/jnsgruk/pytouchlinesl/actions/workflows/test.yaml/badge.svg"></a>
|
|
24
|
+
|
|
25
|
+
Roth TouchlineSL is a control system for underfloor heating, cooling and radiator control. They
|
|
26
|
+
have a public API which is documented on [their
|
|
27
|
+
website](https://api-documentation.roth-touchlinesl.com/).
|
|
28
|
+
|
|
29
|
+
This project provides a Python client for interacting with the API, and controlling heating
|
|
30
|
+
systems. It does not have complete coverage of the API, and currently provides the facility to:
|
|
31
|
+
|
|
32
|
+
- Authenticate with a https://roth-touchlinesl.com account
|
|
33
|
+
- List modules associated with an account
|
|
34
|
+
- Get details of individual zones
|
|
35
|
+
- Get details of global heating schedules
|
|
36
|
+
- Set a constant target temperature for a zone
|
|
37
|
+
- Assign a zone to a specific global schedule
|
|
38
|
+
|
|
39
|
+
The library was designed primarily to support the development of a [Home
|
|
40
|
+
Assistant](https://home-assistant.io/) integration.
|
|
41
|
+
|
|
42
|
+
## Design
|
|
43
|
+
|
|
44
|
+
Roth's API design makes operations on individual zones or schedules quite difficult. Only one
|
|
45
|
+
endpoint is provided for fetching the configuration of zones, and it's the same endpoint that
|
|
46
|
+
returns data for _all_ zones attached to a module.
|
|
47
|
+
|
|
48
|
+
As a result, this client implements some basic caching. Each time the modules endpoint is queried,
|
|
49
|
+
the result is cached for 30 seconds. Any POST requests made (setting temperatures, assigning zones
|
|
50
|
+
to schedules) will invalidate the cache, and all GET methods have a `refresh` argument that can be
|
|
51
|
+
used to force a refresh of the underlying data.
|
|
52
|
+
|
|
53
|
+
## Example Usage
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import asyncio
|
|
57
|
+
import os
|
|
58
|
+
|
|
59
|
+
from pytouchlinesl import TouchlineSL
|
|
60
|
+
|
|
61
|
+
async def touchlinesl_example():
|
|
62
|
+
tsl = TouchlineSL(
|
|
63
|
+
username=os.getenv("TOUCHLINESL_LOGIN"),
|
|
64
|
+
password=os.getenv("TOUCHLINESL_PASSWORD"),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Fetch a list of modules associated with the account
|
|
68
|
+
modules = await tsl.modules()
|
|
69
|
+
module = await tsl.module(module_id=modules[0].id)
|
|
70
|
+
|
|
71
|
+
# Fetch a zone by name, set a constant target temperature of 17.0
|
|
72
|
+
utility = await module.zone_by_name("Utility Room")
|
|
73
|
+
await utility.set_temperature(17.0)
|
|
74
|
+
|
|
75
|
+
# Fetch a zone by ID, assign it to a global schedule named "Living Spaces"
|
|
76
|
+
kitchen = await module.zone(2411)
|
|
77
|
+
living_spaces = await module.schedule_by_name("Living Spaces")
|
|
78
|
+
await kitchen.set_schedule(living_spaces.id)
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
asyncio.set_event_loop(asyncio.new_event_loop())
|
|
82
|
+
asyncio.run(touchlinesl_example())
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Contributing / Hacking
|
|
86
|
+
|
|
87
|
+
Contributions in either code or documentation are welcome. The set of features is limited at the
|
|
88
|
+
moment, but I'm happy to expand as the need arises.
|
|
89
|
+
|
|
90
|
+
The project does not have many dependencies; just `asyncio` and `pytest`/`pytest-asyncio` for
|
|
91
|
+
testing.
|
|
92
|
+
|
|
93
|
+
Dependencies are managed using [`uv`](https://github.com/astral-sh/uv). You can get started like
|
|
94
|
+
so:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Clone the repository
|
|
98
|
+
git clone https://github.com/jnsgruk/pytouchlinesl
|
|
99
|
+
cd pytouchlinesl
|
|
100
|
+
|
|
101
|
+
# Run the tests
|
|
102
|
+
uv run pytest
|
|
103
|
+
# Lint the code
|
|
104
|
+
uv run ruff check --fix
|
|
105
|
+
# Format the code
|
|
106
|
+
uv run ruff format
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If you'd rather use standard Python tooling, you can do so:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
# Clone the repository
|
|
113
|
+
git clone https://github.com/jnsgruk/pytouchlinesl
|
|
114
|
+
cd pytouchlinesl
|
|
115
|
+
|
|
116
|
+
# Create a virtual environment
|
|
117
|
+
python3 -m venv .venv
|
|
118
|
+
source .venv/bin/activate
|
|
119
|
+
|
|
120
|
+
# Install dev/project dependencies
|
|
121
|
+
pip install -e '.[dev]'
|
|
122
|
+
|
|
123
|
+
# Run the tests
|
|
124
|
+
pytest -s
|
|
125
|
+
# Lint the code
|
|
126
|
+
ruff check --fix
|
|
127
|
+
# Format the code
|
|
128
|
+
ruff format
|
|
129
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
pytouchlinesl/__init__.py,sha256=Hb5ZUn4eD8UsDhRsFn5czprZ0yrdbw7h-kIzoHi4yuY,192
|
|
2
|
+
pytouchlinesl/module.py,sha256=q4lcifSdiMNdGLj9l0s3XhdjDMRlia1-pgIIEhkHEBg,6844
|
|
3
|
+
pytouchlinesl/touchlinesl.py,sha256=dc_SjmrnU0-SnXE631xaFgIh-qqYxwxKSuHVYAq1bck,2690
|
|
4
|
+
pytouchlinesl/zone.py,sha256=HQEciHY_jyJYgPo9MNoW40I-d-rutOmXWS_ZxNjbvI4,4067
|
|
5
|
+
pytouchlinesl/client/__init__.py,sha256=yOrMiUGs0Y0pB9QUC0RA5S20fCb895W1x4PBmy1a7pA,135
|
|
6
|
+
pytouchlinesl/client/base.py,sha256=2bLiRAPVqWrLzTwQgkfZTFhRMbCxrA1KGFGnWUlrwxY,1311
|
|
7
|
+
pytouchlinesl/client/client.py,sha256=nLrxFWRGhx3q7KCt2IH_BeDuf3xIzZUnXVHTSx6HsAs,7264
|
|
8
|
+
pytouchlinesl/client/models/__init__.py,sha256=jAhtomuQjVdrfvGEH9MOR3Op8AIXuZuX4D5rJJnAr1Y,462
|
|
9
|
+
pytouchlinesl/client/models/models.py,sha256=AW1qdCSuEe9zDdsDcSldZV_wFArECHLqzowOARKWOIY,5886
|
|
10
|
+
pytouchlinesl-0.1.0.dist-info/LICENSE,sha256=9n5oRexOCNjfxF5oX_6CT15lM0WvMm6tk8W97S_dStM,11335
|
|
11
|
+
pytouchlinesl-0.1.0.dist-info/METADATA,sha256=DB63bUVeQGnkqWU1wY5hydfs6M4lnG-splsjl2455xU,4267
|
|
12
|
+
pytouchlinesl-0.1.0.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
|
13
|
+
pytouchlinesl-0.1.0.dist-info/top_level.txt,sha256=6nQnwOgT46BcqACOyun_n73jkjOdnPNiAHxptPxaw38,14
|
|
14
|
+
pytouchlinesl-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytouchlinesl
|