emerald-hws 0.0.18__py3-none-any.whl → 0.0.19__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.
emerald_hws/emeraldhws.py CHANGED
@@ -109,10 +109,29 @@ class EmeraldHWS():
109
109
 
110
110
  if post_response_json.get("code") == 200:
111
111
  self.logger.debug("emeraldhws: Successfully logged into Emerald API")
112
- self.properties = post_response_json.get("info").get("property")
112
+ with self._state_lock:
113
+ self.properties = post_response_json.get("info").get("property")
113
114
  else:
114
115
  raise Exception("Unable to fetch properties from Emerald API")
115
116
 
117
+ def _wait_for_properties(self, timeout=30):
118
+ """
119
+ Wait for properties to be populated and return a thread-safe copy.
120
+ Blocks until properties is a non-empty list or timeout occurs.
121
+
122
+ :param timeout: Maximum seconds to wait
123
+ :returns: List of properties
124
+ :raises: Exception if timeout or properties not available
125
+ """
126
+ start_time = time.time()
127
+ while time.time() - start_time < timeout:
128
+ with self._state_lock:
129
+ if isinstance(self.properties, list) and len(self.properties) > 0:
130
+ return list(self.properties) # Return a copy
131
+ time.sleep(0.1) # Small delay before retry
132
+
133
+ raise Exception("Timeout waiting for properties to be populated")
134
+
116
135
  def replaceCallback(self, update_callback):
117
136
  """ Replaces the current registered update callback (if any) with the supplied
118
137
  """
@@ -555,9 +574,10 @@ class EmeraldHWS():
555
574
  if not self._is_connected:
556
575
  self.connect()
557
576
 
577
+ properties_list = self._wait_for_properties()
558
578
  hws = []
559
579
 
560
- for properties in self.properties:
580
+ for properties in properties_list:
561
581
  heat_pumps = properties.get('heat_pump', [])
562
582
  for heat_pump in heat_pumps:
563
583
  hws.append(heat_pump["id"])
@@ -568,10 +588,8 @@ class EmeraldHWS():
568
588
  """ Subscribes to updates from all detected HWS
569
589
  """
570
590
 
571
- if not self.properties:
572
- self.getAllHWS()
573
-
574
- for property in self.properties:
591
+ properties_list = self._wait_for_properties()
592
+ for property in properties_list:
575
593
  for hws in property.get("heat_pump"):
576
594
  self.subscribeForUpdates(hws.get("id"))
577
595
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: emerald_hws
3
- Version: 0.0.18
3
+ Version: 0.0.19
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
@@ -0,0 +1,7 @@
1
+ emerald_hws/__init__.py,sha256=uukjQ-kiPYKWvGT3jLL6kJA1DCNAxtw4HlLKqPSypXs,61
2
+ emerald_hws/emeraldhws.py,sha256=Zew-LUriunMceTCRm28ysQ6-wL-wkS8WEWKCn_x9dXQ,27452
3
+ emerald_hws/__assets__/SFSRootCAG2.pem,sha256=hw9W0AnYrrlbcWsOewAgIl1ULEsoO57Ylu35dCjWcS4,1424
4
+ emerald_hws-0.0.19.dist-info/METADATA,sha256=I5ed2dPU2OO9eO9UMZmSKgscxm_uyqp2g9i3VGcKgYQ,2534
5
+ emerald_hws-0.0.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ emerald_hws-0.0.19.dist-info/top_level.txt,sha256=ZCiUmnBkDr2n4QVkTet1s_AKiGJjuz3heuCR5w5ZqLY,12
7
+ emerald_hws-0.0.19.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- emerald_hws/__init__.py,sha256=uukjQ-kiPYKWvGT3jLL6kJA1DCNAxtw4HlLKqPSypXs,61
2
- emerald_hws/emeraldhws.py,sha256=_kW1CtCrhfUW7AXhzTdqO7TSSKQe_Oxw9q5v6qiPx_Q,26598
3
- emerald_hws/__assets__/SFSRootCAG2.pem,sha256=hw9W0AnYrrlbcWsOewAgIl1ULEsoO57Ylu35dCjWcS4,1424
4
- emerald_hws-0.0.18.dist-info/METADATA,sha256=gmRQmS3lp6IcJbb6jPCAYrn4sY7gY5GWln4a9x8VToY,2534
5
- emerald_hws-0.0.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- emerald_hws-0.0.18.dist-info/top_level.txt,sha256=ZCiUmnBkDr2n4QVkTet1s_AKiGJjuz3heuCR5w5ZqLY,12
7
- emerald_hws-0.0.18.dist-info/RECORD,,