pytouchlinesl 0.2.0__tar.gz → 0.3.0__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.
- {pytouchlinesl-0.2.0/pytouchlinesl.egg-info → pytouchlinesl-0.3.0}/PKG-INFO +1 -1
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pyproject.toml +1 -1
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/module.py +9 -10
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/touchlinesl.py +11 -4
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0/pytouchlinesl.egg-info}/PKG-INFO +1 -1
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_module.py +20 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_touchlinesl.py +9 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/LICENSE +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/README.md +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/__init__.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/__init__.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/base.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/client.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/models/__init__.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/models/models.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/zone.py +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/SOURCES.txt +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/dependency_links.txt +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/requires.txt +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/top_level.txt +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/setup.cfg +0 -0
- {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_zone.py +0 -0
|
@@ -62,7 +62,7 @@ class Module:
|
|
|
62
62
|
self._raw_data: ModuleModel
|
|
63
63
|
# Unix timestamp representing the last time the _raw_data was fetched
|
|
64
64
|
self._last_fetched = 0
|
|
65
|
-
self._cache_validity = cache_validity
|
|
65
|
+
self._cache_validity = cache_validity * 1000
|
|
66
66
|
|
|
67
67
|
self._zones: list[Zone] = []
|
|
68
68
|
self._schedules: list[GlobalScheduleModel] = []
|
|
@@ -96,13 +96,13 @@ class Module:
|
|
|
96
96
|
include_off: (Optional) Include zones which are switched off in the results.
|
|
97
97
|
refresh: (Optional) Force the data to be refreshed using the API.
|
|
98
98
|
"""
|
|
99
|
-
|
|
100
|
-
data = await self._data(refresh=refresh)
|
|
99
|
+
data = await self._data(refresh=refresh)
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
self._zones = []
|
|
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
106
|
|
|
107
107
|
if include_off:
|
|
108
108
|
return self._zones
|
|
@@ -136,9 +136,8 @@ class Module:
|
|
|
136
136
|
Args:
|
|
137
137
|
refresh: (Optional) Force the data to be refreshed using the API.
|
|
138
138
|
"""
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
self._schedules = data.zones.global_schedules.elements
|
|
139
|
+
data = await self._data(refresh=refresh)
|
|
140
|
+
self._schedules = data.zones.global_schedules.elements
|
|
142
141
|
|
|
143
142
|
return self._schedules
|
|
144
143
|
|
|
@@ -31,13 +31,15 @@ class TouchlineSL:
|
|
|
31
31
|
username: str | None = None,
|
|
32
32
|
password: str | None = None,
|
|
33
33
|
client: BaseClient | None = None,
|
|
34
|
+
cache_validity: int = 30,
|
|
34
35
|
):
|
|
35
36
|
"""Construct the instance with either credentials or an authenticated client.
|
|
36
37
|
|
|
37
38
|
Args:
|
|
38
|
-
username:
|
|
39
|
-
password:
|
|
40
|
-
client:
|
|
39
|
+
username: (Optional) Username for TouchlineSL account. Ignored if client is passed.
|
|
40
|
+
password: (Optional) Password for TouchlineSL account. Ignored if client is passed.
|
|
41
|
+
client: (Optional) An instance of a RothAPI class.
|
|
42
|
+
cache_validity: (Optional) The number of seconds for which module data should be cached.
|
|
41
43
|
"""
|
|
42
44
|
self._modules: list[Module] = []
|
|
43
45
|
|
|
@@ -52,6 +54,8 @@ class TouchlineSL:
|
|
|
52
54
|
raise TypeError("username and password must be strings if no client is provided")
|
|
53
55
|
self._client = RothAPI(username=username, password=password)
|
|
54
56
|
|
|
57
|
+
self._cache_validity = cache_validity
|
|
58
|
+
|
|
55
59
|
async def user_id(self) -> int:
|
|
56
60
|
"""Return the unique user ID of the authenticated account."""
|
|
57
61
|
return await self._client.user_id()
|
|
@@ -64,7 +68,10 @@ class TouchlineSL:
|
|
|
64
68
|
"""
|
|
65
69
|
if not self._modules or refresh:
|
|
66
70
|
data = await self._client.modules()
|
|
67
|
-
self._modules = [
|
|
71
|
+
self._modules = [
|
|
72
|
+
Module(client=self._client, module_data=m, cache_validity=self._cache_validity)
|
|
73
|
+
for m in data
|
|
74
|
+
]
|
|
68
75
|
|
|
69
76
|
return self._modules
|
|
70
77
|
|
|
@@ -45,6 +45,16 @@ async def test_zones_cache(test_module):
|
|
|
45
45
|
assert initial_fetch_time == test_module._last_fetched
|
|
46
46
|
|
|
47
47
|
|
|
48
|
+
@pytest.mark.asyncio
|
|
49
|
+
async def test_zones_cache_expired(test_module_short_cache):
|
|
50
|
+
await test_module_short_cache.zones()
|
|
51
|
+
initial_fetch_time = test_module_short_cache._last_fetched
|
|
52
|
+
await asyncio.sleep(0.25)
|
|
53
|
+
|
|
54
|
+
await test_module_short_cache.zones()
|
|
55
|
+
assert initial_fetch_time != test_module_short_cache._last_fetched
|
|
56
|
+
|
|
57
|
+
|
|
48
58
|
@pytest.mark.asyncio
|
|
49
59
|
async def test_zones_force_refresh(test_module):
|
|
50
60
|
await test_module.zones()
|
|
@@ -119,6 +129,16 @@ async def test_schedules_cache(test_module):
|
|
|
119
129
|
assert initial_fetch_time == test_module._last_fetched
|
|
120
130
|
|
|
121
131
|
|
|
132
|
+
@pytest.mark.asyncio
|
|
133
|
+
async def test_schedules_cache_expired(test_module_short_cache):
|
|
134
|
+
await test_module_short_cache.schedules()
|
|
135
|
+
initial_fetch_time = test_module_short_cache._last_fetched
|
|
136
|
+
await asyncio.sleep(0.5)
|
|
137
|
+
|
|
138
|
+
await test_module_short_cache.schedules()
|
|
139
|
+
assert initial_fetch_time != test_module_short_cache._last_fetched
|
|
140
|
+
|
|
141
|
+
|
|
122
142
|
@pytest.mark.asyncio
|
|
123
143
|
async def test_schedules_force_refresh(test_module):
|
|
124
144
|
await test_module.schedules()
|
|
@@ -40,6 +40,15 @@ async def test_modules(test_touchlinesl: TouchlineSL):
|
|
|
40
40
|
modules = await test_touchlinesl.modules()
|
|
41
41
|
for m in modules:
|
|
42
42
|
assert isinstance(m, Module)
|
|
43
|
+
assert m._cache_validity == 30000
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.mark.asyncio
|
|
47
|
+
async def test_modules_short_cache(test_touchlinesl_short_cache: TouchlineSL):
|
|
48
|
+
modules = await test_touchlinesl_short_cache.modules()
|
|
49
|
+
for m in modules:
|
|
50
|
+
assert isinstance(m, Module)
|
|
51
|
+
assert m._cache_validity == 100
|
|
43
52
|
|
|
44
53
|
|
|
45
54
|
@pytest.mark.asyncio
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|