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.
Files changed (22) hide show
  1. {pytouchlinesl-0.2.0/pytouchlinesl.egg-info → pytouchlinesl-0.3.0}/PKG-INFO +1 -1
  2. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pyproject.toml +1 -1
  3. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/module.py +9 -10
  4. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/touchlinesl.py +11 -4
  5. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0/pytouchlinesl.egg-info}/PKG-INFO +1 -1
  6. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_module.py +20 -0
  7. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_touchlinesl.py +9 -0
  8. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/LICENSE +0 -0
  9. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/README.md +0 -0
  10. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/__init__.py +0 -0
  11. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/__init__.py +0 -0
  12. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/base.py +0 -0
  13. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/client.py +0 -0
  14. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/models/__init__.py +0 -0
  15. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/client/models/models.py +0 -0
  16. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl/zone.py +0 -0
  17. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/SOURCES.txt +0 -0
  18. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/dependency_links.txt +0 -0
  19. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/requires.txt +0 -0
  20. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/pytouchlinesl.egg-info/top_level.txt +0 -0
  21. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/setup.cfg +0 -0
  22. {pytouchlinesl-0.2.0 → pytouchlinesl-0.3.0}/tests/test_zone.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytouchlinesl
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: An API client for Roth's TouchlineSL control system.
5
5
  Author-email: Jon Seager <jon@sgrs.uk>
6
6
  Project-URL: Homepage, https://github.com/jnsgruk/pytouchlinesl
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytouchlinesl"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  authors = [{ name = "Jon Seager", email = "jon@sgrs.uk" }]
5
5
  description = "An API client for Roth's TouchlineSL control system."
6
6
  readme = "README.md"
@@ -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
- if not self._zones or refresh:
100
- data = await self._data(refresh=refresh)
99
+ data = await self._data(refresh=refresh)
101
100
 
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)
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
- if not self._schedules or refresh:
140
- data = await self._data(refresh=refresh)
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: (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.
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 = [Module(client=self._client, module_data=m) for m in data]
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytouchlinesl
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: An API client for Roth's TouchlineSL control system.
5
5
  Author-email: Jon Seager <jon@sgrs.uk>
6
6
  Project-URL: Homepage, https://github.com/jnsgruk/pytouchlinesl
@@ -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