violet-poolController-api 0.0.11__tar.gz → 0.0.14__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 (19) hide show
  1. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/PKG-INFO +1 -1
  2. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/pyproject.toml +1 -1
  3. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/setup.py +1 -1
  4. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/tests/test_api.py +106 -5
  5. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolController_api.egg-info/PKG-INFO +1 -1
  6. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/api.py +33 -8
  7. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/LICENSE +0 -0
  8. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/README.md +0 -0
  9. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/setup.cfg +0 -0
  10. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolController_api.egg-info/SOURCES.txt +0 -0
  11. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolController_api.egg-info/dependency_links.txt +0 -0
  12. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolController_api.egg-info/requires.txt +0 -0
  13. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolController_api.egg-info/top_level.txt +0 -0
  14. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/__init__.py +0 -0
  15. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/circuit_breaker.py +0 -0
  16. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/const_api.py +0 -0
  17. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/const_devices.py +0 -0
  18. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/utils_rate_limiter.py +0 -0
  19. {violet_poolcontroller_api-0.0.11 → violet_poolcontroller_api-0.0.14}/violet_poolcontroller_api/utils_sanitizer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: violet-poolController-api
3
- Version: 0.0.11
3
+ Version: 0.0.14
4
4
  Summary: Asynchronous Python client for the Violet Pool Controller.
5
5
  Home-page: https://github.com/Xerolux/violet-poolController-api
6
6
  Author: Basti (Xerolux)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "violet-poolController-api"
7
- version = "0.0.11"
7
+ version = "0.0.14"
8
8
  authors = [
9
9
  { name="Basti (Xerolux)", email="git@xerolux.de" },
10
10
  ]
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup, find_packages
2
2
  setup(
3
3
  name="violet-poolController-api",
4
- version="0.0.11",
4
+ version="0.0.14",
5
5
  author="Basti (Xerolux)",
6
6
  author_email="git@xerolux.de",
7
7
  description="Asynchronous Python client for the Violet Pool Controller.",
@@ -257,7 +257,7 @@ async def test_dosing_standalone_detection_dict_format(mock_aioresponse, standal
257
257
 
258
258
  @pytest.mark.asyncio
259
259
  async def test_get_hardware_profile(mock_aioresponse, api_client):
260
- """Test get_hardware_profile correctly detects components."""
260
+ """Test get_hardware_profile correctly detects components via alive counters."""
261
261
  url = "http://192.168.1.100/getReadings?ALL"
262
262
 
263
263
  # 1. Base module only (no DOS, EXT)
@@ -270,8 +270,14 @@ async def test_get_hardware_profile(mock_aioresponse, api_client):
270
270
  "extension_module_2": False,
271
271
  }
272
272
 
273
- # 2. Base module + Dosing + Ext1
274
- mock_aioresponse.get(url, payload={"getReadings": {"PUMPSTATE": "2", "SYSTEM_dosagemodule_cpu_temperature": 45.5, "EXT1_1": "1"}}, status=200)
273
+ # 2. Base module + Dosing + Ext1 (via alive counters)
274
+ mock_aioresponse.get(url, payload={"getReadings": {
275
+ "PUMPSTATE": "2",
276
+ "SYSTEM_dosagemodule_alive_count": "20392243",
277
+ "SYSTEM_dosagemodule_cpu_temperature": 45.5,
278
+ "SYSTEM_ext1module_alive_count": "52443888",
279
+ "EXT1_1": "1",
280
+ }}, status=200)
275
281
  profile = await api_client.get_hardware_profile()
276
282
  assert profile == {
277
283
  "base_module": True,
@@ -280,8 +286,14 @@ async def test_get_hardware_profile(mock_aioresponse, api_client):
280
286
  "extension_module_2": False,
281
287
  }
282
288
 
283
- # 3. Base module + Ext1 + Ext2 (no Dosing)
284
- mock_aioresponse.get(url, payload={"getReadings": {"PUMPSTATE": "2", "EXT1_1": "1", "EXT2_1": "1"}}, status=200)
289
+ # 3. Base module + Ext1 + Ext2 (via alive counters, no Dosing)
290
+ mock_aioresponse.get(url, payload={"getReadings": {
291
+ "PUMPSTATE": "2",
292
+ "SYSTEM_ext1module_alive_count": "100",
293
+ "SYSTEM_ext2module_alive_count": "200",
294
+ "EXT1_1": "1",
295
+ "EXT2_1": "1",
296
+ }}, status=200)
285
297
  profile = await api_client.get_hardware_profile()
286
298
  assert profile == {
287
299
  "base_module": True,
@@ -290,6 +302,95 @@ async def test_get_hardware_profile(mock_aioresponse, api_client):
290
302
  "extension_module_2": True,
291
303
  }
292
304
 
305
+ # 4. Real-world scenario: EXT2 relay data present (value 0) but no ext2 module
306
+ # Controller always returns EXT2_* keys even when the module is absent.
307
+ mock_aioresponse.get(url, payload={"getReadings": {
308
+ "PUMPSTATE": "2",
309
+ "SYSTEM_dosagemodule_alive_count": "20392243",
310
+ "SYSTEM_ext1module_alive_count": "52443888",
311
+ "EXT1_1": 0, "EXT1_2": 0,
312
+ "EXT2_1": 0, "EXT2_2": 0,
313
+ "EXT2_1_LAST_ON": 0, "EXT2_1_LAST_OFF": 0,
314
+ }}, status=200)
315
+ profile = await api_client.get_hardware_profile()
316
+ assert profile["extension_module_1"] is True
317
+ assert profile["extension_module_2"] is False
318
+
319
+ @pytest.mark.asyncio
320
+ async def test_set_switch_state_ext1_relay(mock_aioresponse, api_client):
321
+ """Test set_switch_state sends correct URL for EXT1_2 ON, OFF, and AUTO."""
322
+ base = "http://192.168.1.100/setFunctionManually"
323
+
324
+ mock_aioresponse.get(f"{base}?EXT1_2,ON,0,0", body="OK", status=200)
325
+ result = await api_client.set_switch_state("EXT1_2", "ON")
326
+ assert result["success"] is True
327
+
328
+ mock_aioresponse.get(f"{base}?EXT1_2,OFF,0,0", body="OK", status=200)
329
+ result = await api_client.set_switch_state("EXT1_2", "OFF")
330
+ assert result["success"] is True
331
+
332
+ mock_aioresponse.get(f"{base}?EXT1_2,AUTO,0,0", body="OK", status=200)
333
+ result = await api_client.set_switch_state("EXT1_2", "AUTO")
334
+ assert result["success"] is True
335
+
336
+
337
+ @pytest.mark.asyncio
338
+ async def test_module_alive_on_zero_count(mock_aioresponse, api_client):
339
+ """EXT1 module must be detected when alive_count key is present but value is 0.
340
+
341
+ The alive counter starts at 0 immediately after a controller restart. The
342
+ old code required value > 0, which caused EXT1_* readings to be filtered
343
+ and the relay switch to appear broken right after a restart.
344
+ """
345
+ url = "http://192.168.1.100/getReadings?ALL"
346
+ mock_aioresponse.get(url, payload={"getReadings": {
347
+ "PUMPSTATE": "2",
348
+ "SYSTEM_ext1module_alive_count": "0",
349
+ "EXT1_1": 0,
350
+ "EXT1_2": 0,
351
+ }}, status=200)
352
+
353
+ result = await api_client.get_readings()
354
+ assert "EXT1_2" in result, (
355
+ "EXT1_2 must not be filtered when SYSTEM_ext1module_alive_count is present, "
356
+ "even if the counter is still 0 after a restart"
357
+ )
358
+
359
+
360
+ @pytest.mark.asyncio
361
+ async def test_ext1_readings_not_filtered_when_detected(mock_aioresponse, api_client):
362
+ """EXT1_* readings are included when extension_module_1 is detected."""
363
+ url = "http://192.168.1.100/getReadings?ALL"
364
+ mock_aioresponse.get(url, payload={"getReadings": {
365
+ "PUMPSTATE": "2",
366
+ "SYSTEM_ext1module_alive_count": "12345",
367
+ "EXT1_1": 1,
368
+ "EXT1_2": 0,
369
+ "EXT1_3": 0,
370
+ }}, status=200)
371
+
372
+ result = await api_client.get_readings()
373
+ assert "EXT1_1" in result
374
+ assert "EXT1_2" in result
375
+ assert "EXT1_3" in result
376
+
377
+
378
+ @pytest.mark.asyncio
379
+ async def test_ext1_readings_filtered_when_not_detected(mock_aioresponse, api_client):
380
+ """EXT1_* readings are stripped when extension_module_1 key is absent."""
381
+ url = "http://192.168.1.100/getReadings?ALL"
382
+ mock_aioresponse.get(url, payload={"getReadings": {
383
+ "PUMPSTATE": "2",
384
+ # No SYSTEM_ext1module_alive_count → module not connected
385
+ "EXT1_1": 0,
386
+ "EXT1_2": 0,
387
+ }}, status=200)
388
+
389
+ result = await api_client.get_readings()
390
+ assert "EXT1_1" not in result
391
+ assert "EXT1_2" not in result
392
+
393
+
293
394
  @pytest.mark.asyncio
294
395
  async def test_get_hardware_profile_standalone_dosing(mock_aioresponse, standalone_api_client):
295
396
  """Test get_hardware_profile with a standalone dosing configuration."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: violet-poolController-api
3
- Version: 0.0.11
3
+ Version: 0.0.14
4
4
  Summary: Asynchronous Python client for the Violet Pool Controller.
5
5
  Home-page: https://github.com/Xerolux/violet-poolController-api
6
6
  Author: Basti (Xerolux)
@@ -500,23 +500,48 @@ class VioletPoolAPI:
500
500
  def _build_hardware_profile(self, flattened: dict[str, Any]) -> dict[str, bool]:
501
501
  """Build a hardware presence profile from flattened getReadings data.
502
502
 
503
+ Uses the controller's alive-counters (``SYSTEM_*_alive_count``) to
504
+ reliably detect connected hardware modules. The controller always
505
+ emits relay keys (``EXT1_1``, ``EXT2_1``, …) with a default value of
506
+ ``0`` even when the physical module is absent, so checking those keys
507
+ would yield false positives.
508
+
503
509
  Args:
504
510
  flattened: The flattened key-value readings dict.
505
511
 
506
512
  Returns:
507
513
  A dictionary with boolean flags for connected hardware components.
508
514
  """
509
- def is_present(key: str) -> bool:
510
- if not isinstance(flattened, dict):
511
- return False
512
- val = flattened.get(key)
513
- return val is not None and str(val).strip().upper() != "N/A"
515
+ def _module_alive(alive_key: str) -> bool:
516
+ # Key presence means the module is connected; the counter starts at 0
517
+ # on boot and the controller only emits alive-count keys for modules
518
+ # that are physically attached, so checking value > 0 would produce
519
+ # false negatives immediately after a controller restart.
520
+ return alive_key in flattened
521
+
522
+ def _any_relay_used(prefix: str) -> bool:
523
+ for key, val in flattened.items():
524
+ if not key.startswith(prefix):
525
+ continue
526
+ if "_LAST_ON" not in key and "_LAST_OFF" not in key and "_RUNTIME" not in key:
527
+ last_on = flattened.get(f"{key}_LAST_ON")
528
+ if last_on is not None:
529
+ try:
530
+ if float(str(last_on).strip()) > 0:
531
+ return True
532
+ except (ValueError, TypeError):
533
+ pass
534
+ return False
535
+
536
+ ext1 = _module_alive("SYSTEM_ext1module_alive_count") or _any_relay_used("EXT1_")
537
+ ext2 = _module_alive("SYSTEM_ext2module_alive_count") or _any_relay_used("EXT2_")
538
+ dosing = self.dosing_standalone or _module_alive("SYSTEM_dosagemodule_alive_count")
514
539
 
515
540
  return {
516
541
  "base_module": not self.dosing_standalone,
517
- "dosing_module": self.dosing_standalone or is_present("SYSTEM_dosagemodule_cpu_temperature"),
518
- "extension_module_1": is_present("EXT1_1"),
519
- "extension_module_2": is_present("EXT2_1"),
542
+ "dosing_module": dosing,
543
+ "extension_module_1": ext1,
544
+ "extension_module_2": ext2,
520
545
  }
521
546
 
522
547
  async def get_readings(self) -> dict[str, Any]: