emerald-hws 0.0.14__tar.gz → 0.0.15__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.
@@ -18,7 +18,7 @@ jobs:
18
18
  uses: "actions/checkout@v5"
19
19
 
20
20
  - name: "Set up Python"
21
- uses: actions/setup-python@v5.6.0
21
+ uses: actions/setup-python@v6
22
22
  with:
23
23
  python-version: "3.11"
24
24
  cache: "pip"
@@ -70,7 +70,7 @@ jobs:
70
70
  fetch-depth: 0
71
71
 
72
72
  - name: "Set up Python"
73
- uses: "actions/setup-python@v5"
73
+ uses: "actions/setup-python@v6"
74
74
  with:
75
75
  python-version: "3.11"
76
76
  cache: "pip"
@@ -114,7 +114,7 @@ jobs:
114
114
  fetch-depth: 0
115
115
 
116
116
  - name: "Set up Python"
117
- uses: "actions/setup-python@v5"
117
+ uses: "actions/setup-python@v6"
118
118
  with:
119
119
  python-version: "3.11"
120
120
  cache: "pip"
@@ -22,7 +22,7 @@ jobs:
22
22
  uses: "actions/checkout@v5"
23
23
 
24
24
  - name: "Set up Python ${{ matrix.python-version }}"
25
- uses: "actions/setup-python@v5"
25
+ uses: "actions/setup-python@v6"
26
26
  with:
27
27
  python-version: ${{ matrix.python-version }}
28
28
  cache: "pip"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: emerald_hws
3
- Version: 0.0.14
3
+ Version: 0.0.15
4
4
  Summary: A package to manipulate and monitor Emerald Heat Pump Hot Water Systems
5
5
  Author-email: Ross Williamson <ross@inertia.net.nz>
6
6
  License-Expression: MIT
@@ -39,6 +39,7 @@ class EmeraldHWS():
39
39
  self.properties = {}
40
40
  self.logger = logging.getLogger(__name__)
41
41
  self.update_callback = update_callback
42
+ self._state_lock = threading.RLock() # Thread-safe lock for state operations
42
43
 
43
44
  # Convert minutes to seconds for internal use
44
45
  self.connection_timeout = connection_timeout_minutes * 60.0
@@ -332,11 +333,14 @@ class EmeraldHWS():
332
333
  :param value: value to set
333
334
  """
334
335
 
335
- for properties in self.properties:
336
- heat_pumps = properties.get('heat_pump', [])
337
- for heat_pump in heat_pumps:
338
- if heat_pump['id'] == id:
339
- heat_pump['last_state'][key] = value
336
+ with self._state_lock:
337
+ for properties in self.properties:
338
+ heat_pumps = properties.get('heat_pump', [])
339
+ for heat_pump in heat_pumps:
340
+ if heat_pump['id'] == id:
341
+ heat_pump['last_state'][key] = value
342
+
343
+ # Call callback AFTER releasing lock to avoid potential deadlocks
340
344
  if self.update_callback is not None:
341
345
  self.update_callback()
342
346
 
@@ -365,11 +369,13 @@ class EmeraldHWS():
365
369
  if not self.properties:
366
370
  self.connect()
367
371
 
368
- for properties in self.properties:
369
- heat_pumps = properties.get('heat_pump', [])
370
- for heat_pump in heat_pumps:
371
- if heat_pump['id'] == id:
372
- return heat_pump
372
+ with self._state_lock:
373
+ for properties in self.properties:
374
+ heat_pumps = properties.get('heat_pump', [])
375
+ for heat_pump in heat_pumps:
376
+ if heat_pump['id'] == id:
377
+ return heat_pump
378
+ return None
373
379
 
374
380
  def sendControlMessage(self, id, payload):
375
381
  """ Sends a message via MQTT to the HWS
@@ -381,6 +387,8 @@ class EmeraldHWS():
381
387
  self.connect()
382
388
 
383
389
  hwsdetail = self.getFullStatus(id)
390
+ if not hwsdetail:
391
+ raise Exception(f"Unable to find HWS with ID {id}")
384
392
 
385
393
  msg = [{"device_id":id,
386
394
  "namespace":"business",
@@ -439,35 +447,45 @@ class EmeraldHWS():
439
447
  """ Returns true if the specified HWS is currently on
440
448
  :param id: The UUID of the HWS to query
441
449
  """
442
- switch_status = self.getFullStatus(id).get("last_state").get("switch")
443
- return (switch_status == 1 or switch_status == "on")
450
+ full_status = self.getFullStatus(id)
451
+ if full_status and full_status.get("last_state"):
452
+ switch_status = full_status.get("last_state").get("switch")
453
+ return (switch_status == 1 or switch_status == "on")
454
+ return False
444
455
 
445
456
  def isHeating(self, id):
446
457
  """ Returns true if the specified HWS is currently heating
447
458
  :param id: The UUID of the HWS to query
448
459
  """
449
- heating_status = self.getFullStatus(id).get("device_operation_status")
450
- return (heating_status == 1)
460
+ full_status = self.getFullStatus(id)
461
+ if full_status:
462
+ heating_status = full_status.get("device_operation_status")
463
+ return (heating_status == 1)
464
+ return False
451
465
 
452
466
  def currentMode(self, id):
453
467
  """ Returns an integer specifying the current mode (0==boost, 1==normal, 2==quiet)
454
468
  :param id: The UUID of the HWS to query
455
469
  """
456
- mode_status = self.getFullStatus(id).get("last_state").get("mode")
457
- return mode_status
470
+ full_status = self.getFullStatus(id)
471
+ if full_status and full_status.get("last_state"):
472
+ mode_status = full_status.get("last_state").get("mode")
473
+ return mode_status
474
+ return None
458
475
 
459
476
  def getInfo(self, id):
460
477
  """ Returns identifying details for the specified HWS
461
478
  :param id: The UUID of the HWS to query
462
479
  """
463
480
  full_status = self.getFullStatus(id)
464
-
465
- return {'id': id,
466
- 'serial_number': full_status.get("serial_number"),
467
- 'brand': full_status.get("brand"),
468
- 'hw_version': full_status.get("hw_version"),
469
- 'soft_version': full_status.get("soft_version")
470
- }
481
+ if full_status:
482
+ return {'id': id,
483
+ 'serial_number': full_status.get("serial_number"),
484
+ 'brand': full_status.get("brand"),
485
+ 'hw_version': full_status.get("hw_version"),
486
+ 'soft_version': full_status.get("soft_version")
487
+ }
488
+ return None
471
489
 
472
490
  def listHWS(self):
473
491
  """ Returns a list of UUIDs of all discovered HWS
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: emerald_hws
3
- Version: 0.0.14
3
+ Version: 0.0.15
4
4
  Summary: A package to manipulate and monitor Emerald Heat Pump Hot Water Systems
5
5
  Author-email: Ross Williamson <ross@inertia.net.nz>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes