python-izone 2.0.0__py3-none-any.whl → 2.0.1__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.
pizone/controller.py CHANGED
@@ -211,10 +211,11 @@ class Controller:
211
211
  self._set_bridge_ok(True)
212
212
 
213
213
  def _nudge_scan(self) -> None:
214
- """Non-blocking cooled-down IASD scan after HTTP transport failure."""
214
+ """Non-blocking cooled-down rediscovery after HTTP transport failure."""
215
215
  if self._closed:
216
216
  return
217
217
  self._discovery_service.schedule_cooled_scan()
218
+ self._discovery_service.schedule_name_check(self._device_uid)
218
219
 
219
220
  @classmethod
220
221
  async def create(
pizone/discovery.py CHANGED
@@ -119,6 +119,15 @@ _FAILURE_RANK = {
119
119
  type _VerifyResult = ControllerEndpoint | UnverifiedEndpoint | None
120
120
 
121
121
 
122
+ def _is_ipv4(host: str) -> bool:
123
+ """Return whether *host* is an IPv4 address rather than a name."""
124
+ try:
125
+ IPv4Address(host)
126
+ except ValueError:
127
+ return False
128
+ return True
129
+
130
+
122
131
  @dataclass(slots=True)
123
132
  class _Entry:
124
133
  state: _State
@@ -128,6 +137,10 @@ class _Entry:
128
137
  # for KNOWN/CLAIMED a move that applies only once it answers.
129
138
  candidate: ControllerEndpoint | None = None
130
139
  verify: Task[_VerifyResult] | None = None
140
+ # CLAIMED only: the name the controller was created from, re-resolved
141
+ # after a transport failure since UDP discovery may not reach the bridge.
142
+ host_name: str | None = None
143
+ last_name_check: float = float("-inf")
131
144
 
132
145
 
133
146
  class DiscoveryService:
@@ -295,6 +308,43 @@ class DiscoveryService:
295
308
 
296
309
  asyncio.get_running_loop().create_task(_run())
297
310
 
311
+ def schedule_name_check(self, uid: str) -> None:
312
+ """Re-resolve a claimed controller's name in the background, if it has one.
313
+
314
+ Repoints the controller when its UID answers at a new address. Cooled
315
+ down per UID.
316
+ """
317
+ if self.is_closed:
318
+ return
319
+ entry = self._entry(uid, _State.CLAIMED)
320
+ if entry is None or (name := entry.host_name) is None:
321
+ return
322
+ now = asyncio.get_running_loop().time()
323
+ if now - entry.last_name_check < RESCAN_COOLDOWN:
324
+ return
325
+ entry.last_name_check = now
326
+
327
+ async def _run() -> None:
328
+ try:
329
+ addresses = await self._resolve(name)
330
+ if entry.endpoint.host in addresses:
331
+ return
332
+ if entry.candidate is not None and entry.candidate.host in addresses:
333
+ return # A UDP verify of that address is already in flight.
334
+ probed = await self._probe_first(addresses, expected_uid=uid)
335
+ if isinstance(probed, _ProbeFailed):
336
+ _LOG.debug(
337
+ "Name %s for %s did not verify: %s", name, uid, probed.failure
338
+ )
339
+ return
340
+ if self.is_closed or self._endpoints.get(uid) is not entry:
341
+ return
342
+ self._apply_verified(probed.endpoint)
343
+ except Exception: # noqa: BLE001
344
+ _LOG.debug("Name check for %s failed", uid, exc_info=True)
345
+
346
+ self.create_task(_run())
347
+
298
348
  def _entry(self, uid: str, *states: _State) -> _Entry | None:
299
349
  """Return the entry for *uid* when it is in one of *states*."""
300
350
  entry = self._endpoints.get(uid)
@@ -429,7 +479,7 @@ class DiscoveryService:
429
479
  if self._discover_all_notified is not None:
430
480
  self._discover_all_notified.add(endpoint.uid)
431
481
 
432
- async def discover_by_host(self, host: str) -> ControllerEndpoint | None:
482
+ async def discover_by_host(self, host: str) -> ControllerEndpoint:
433
483
  """Return the controller endpoint at *host*, an IPv4 address or a name.
434
484
 
435
485
  A name is resolved to IPv4 addresses first; the returned endpoint always
@@ -604,9 +654,10 @@ class DiscoveryService:
604
654
 
605
655
  Preferred entry point after :func:`create_discovery`. One-shot per
606
656
  UID. *host* may be an IPv4 address or a name; a name is resolved and
607
- the controller runs on the IP that answers. HTTP probe is the trust
608
- boundary; callers must handle the device being unreachable even after a
609
- recent discovery notify.
657
+ the controller runs on the IP that answers. The name is resolved again
658
+ after a transport failure, in case the bridge moved. HTTP probe is the
659
+ trust boundary; callers must handle the device being unreachable even
660
+ after a recent discovery notify.
610
661
 
611
662
  Raises:
612
663
  UnpairedBridgeError: If *uid* is the unpaired placeholder (no I/O).
@@ -657,6 +708,9 @@ class DiscoveryService:
657
708
  del self._endpoints[uid]
658
709
  raise
659
710
 
711
+ if not _is_ipv4(host) and (claimed := self._entry(uid, _State.CLAIMED)):
712
+ claimed.host_name = host
713
+
660
714
  if pending_address_changed is not None and on_address_changed is not None:
661
715
  self.schedule_address_changed(on_address_changed, pending_address_changed)
662
716
  return controller
pizone/power.py CHANGED
@@ -148,8 +148,11 @@ class PowerDevice:
148
148
  class PowerGroup:
149
149
  """Grouped power channels."""
150
150
 
151
- def __init__(self, power: Power, channels: Iterable[PowerChannel]) -> None:
151
+ def __init__(
152
+ self, power: Power, group_number: int, channels: Iterable[PowerChannel]
153
+ ) -> None:
152
154
  self._power = power
155
+ self._group_number = group_number
153
156
  self._channels = tuple(channels)
154
157
  devices: set[PowerDevice] = set()
155
158
  for chan in channels:
@@ -159,7 +162,7 @@ class PowerGroup:
159
162
  @property
160
163
  def group_number(self) -> int:
161
164
  """The group id."""
162
- return self._channels[0].group_number or -1
165
+ return self._group_number
163
166
 
164
167
  @property
165
168
  def name(self) -> str:
@@ -218,7 +221,9 @@ class Power:
218
221
  for chan in dev.channels:
219
222
  if chan.group_number is not None:
220
223
  gdict.setdefault(chan.group_number, []).append(chan)
221
- self._groups = tuple(PowerGroup(self, gl) for gl in gdict.values())
224
+ self._groups = tuple(
225
+ PowerGroup(self, number, chans) for number, chans in gdict.items()
226
+ )
222
227
 
223
228
  async def refresh(self) -> bool:
224
229
  """Refresh power usage data from the device.
pizone/version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.0.0'
22
- __version_tuple__ = version_tuple = (2, 0, 0)
21
+ __version__ = version = '2.0.1'
22
+ __version_tuple__ = version_tuple = (2, 0, 1)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-izone
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: A python interface to the iZone airconditioner controller
5
5
  Project-URL: Homepage, https://github.com/Swamp-Ig/pizone
6
6
  Author-email: Penny Wood <pypl@ninjateaparty.com>
@@ -1,15 +1,15 @@
1
1
  pizone/__init__.py,sha256=0mUQKWmIebkS8h5yxgqVOqJAXfmQcESGsnkCh6Dkvbo,2944
2
2
  pizone/const.py,sha256=0skTh6zBe61AJ_57fqdBrxz3aVBM3T4Ak_cPSkOx2Bo,153
3
- pizone/controller.py,sha256=oenlsQ1LnVCQFKCFGUy5yMt9kDW6xhuwOwFGHQ9GjXA,47255
4
- pizone/discovery.py,sha256=raW8FYVsOin8pjHnNq9yJ5va31DXLvAWve6A1l47aPw,41265
3
+ pizone/controller.py,sha256=6XhX5ktUOxNFL1KHz0FnSbxblFhCAA6Z1LvNNUn44sk,47327
4
+ pizone/discovery.py,sha256=UX5IAZTAXEk51nHsCLzFe4W80MZjlm31W8HYfszGuwo,43447
5
5
  pizone/exceptions.py,sha256=gd4Xuo05TDtQRob1F65WWhLBEKhsWveK3nK6w-j8Lr4,3270
6
- pizone/power.py,sha256=1nwdOi6w-FfdctIDtOxYTnQaY0mC2U1K0bUyRV3iMeg,10433
6
+ pizone/power.py,sha256=2ltoFotv3phsRJHXxP9Yu7M4PmvUVi8Q_0KJUVvuGkc,10533
7
7
  pizone/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pizone/types.py,sha256=W7pAoBPw1cDt0V_5MbasgUiz7Iwq0zfdxpH4gHTmzsQ,2860
9
9
  pizone/v2.py,sha256=F-jsKfOVFAtRrjzHeGQcuG48_DJ3C-0sRKE_2urTwEw,19276
10
- pizone/version.py,sha256=M8-womMCm6RC2xFuYRGDGvgpBN64psyQZImZ5vOrGmc,520
10
+ pizone/version.py,sha256=AJvqZqEOrEKVHQbALacgWiM-1U44ZzqQ-ZsR-NbTbjg,520
11
11
  pizone/zone.py,sha256=u6NLmha6fr19_75UOnipkSTQ-PPkhVQ9ivpqRCchq6c,10470
12
- python_izone-2.0.0.dist-info/METADATA,sha256=Im9lkaaMQX3woNBlA7ypmc9qZa4bpHh_sEdDW50QCqQ,4282
13
- python_izone-2.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
14
- python_izone-2.0.0.dist-info/licenses/licence.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
- python_izone-2.0.0.dist-info/RECORD,,
12
+ python_izone-2.0.1.dist-info/METADATA,sha256=VqjyrgX_w8GFyIF35uMQm9dRB3g_BTPouqv_KedB2xg,4282
13
+ python_izone-2.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
14
+ python_izone-2.0.1.dist-info/licenses/licence.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
+ python_izone-2.0.1.dist-info/RECORD,,