emerald-hws 0.0.18__py3-none-any.whl → 0.0.20__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,39 @@ 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
+ property_data = post_response_json.get("info", {}).get("property")
113
+ self.logger.debug(f"emeraldhws: API returned property data: {property_data}")
114
+
115
+ with self._state_lock:
116
+ self.properties = property_data
117
+
118
+ # Check if we got valid data
119
+ if not isinstance(property_data, list) or len(property_data) == 0:
120
+ raise Exception("No heat pumps found on account - API returned empty or invalid property list")
113
121
  else:
114
122
  raise Exception("Unable to fetch properties from Emerald API")
115
123
 
124
+ def _wait_for_properties(self, timeout=30):
125
+ """
126
+ Wait for properties to be populated and return a thread-safe copy.
127
+ Blocks until properties is a non-empty list or timeout occurs.
128
+
129
+ :param timeout: Maximum seconds to wait
130
+ :returns: List of properties
131
+ :raises: Exception if timeout or properties not available
132
+ """
133
+ start_time = time.time()
134
+ while time.time() - start_time < timeout:
135
+ with self._state_lock:
136
+ if isinstance(self.properties, list) and len(self.properties) > 0:
137
+ return list(self.properties) # Return a copy
138
+ time.sleep(0.1) # Small delay before retry
139
+
140
+ # Timeout - provide detailed error message
141
+ with self._state_lock:
142
+ final_value = self.properties
143
+ raise Exception(f"Timeout waiting for properties to be populated. Current value: {type(final_value).__name__} = {final_value}")
144
+
116
145
  def replaceCallback(self, update_callback):
117
146
  """ Replaces the current registered update callback (if any) with the supplied
118
147
  """
@@ -555,9 +584,10 @@ class EmeraldHWS():
555
584
  if not self._is_connected:
556
585
  self.connect()
557
586
 
587
+ properties_list = self._wait_for_properties()
558
588
  hws = []
559
589
 
560
- for properties in self.properties:
590
+ for properties in properties_list:
561
591
  heat_pumps = properties.get('heat_pump', [])
562
592
  for heat_pump in heat_pumps:
563
593
  hws.append(heat_pump["id"])
@@ -568,10 +598,8 @@ class EmeraldHWS():
568
598
  """ Subscribes to updates from all detected HWS
569
599
  """
570
600
 
571
- if not self.properties:
572
- self.getAllHWS()
573
-
574
- for property in self.properties:
601
+ properties_list = self._wait_for_properties()
602
+ for property in properties_list:
575
603
  for hws in property.get("heat_pump"):
576
604
  self.subscribeForUpdates(hws.get("id"))
577
605
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: emerald_hws
3
- Version: 0.0.18
3
+ Version: 0.0.20
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=fVyZ_9uQp9RfHTaAI0ZlHIj37hIn2lHDNeXO0vysV4I,28008
3
+ emerald_hws/__assets__/SFSRootCAG2.pem,sha256=hw9W0AnYrrlbcWsOewAgIl1ULEsoO57Ylu35dCjWcS4,1424
4
+ emerald_hws-0.0.20.dist-info/METADATA,sha256=UE32BxNZQMJmdZ62Q-CXOOr0u76QMVoMoUQfpDWtvOE,2534
5
+ emerald_hws-0.0.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ emerald_hws-0.0.20.dist-info/top_level.txt,sha256=ZCiUmnBkDr2n4QVkTet1s_AKiGJjuz3heuCR5w5ZqLY,12
7
+ emerald_hws-0.0.20.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,,