pypck 0.8.8__py3-none-any.whl → 0.8.10__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.
pypck/connection.py CHANGED
@@ -13,7 +13,7 @@ from pypck import inputs, lcn_defs
13
13
  from pypck.helpers import TaskRegistry
14
14
  from pypck.lcn_addr import LcnAddr
15
15
  from pypck.lcn_defs import LcnEvent
16
- from pypck.module import AbstractConnection, GroupConnection, ModuleConnection
16
+ from pypck.module import GroupConnection, ModuleConnection
17
17
  from pypck.pck_commands import PckGenerator
18
18
 
19
19
  _LOGGER = logging.getLogger(__name__)
@@ -243,7 +243,7 @@ class PchkConnectionManager:
243
243
  if isinstance(exc, (ConnectionRefusedError, OSError)):
244
244
  raise PchkConnectionRefusedError()
245
245
  else:
246
- raise awaitable.exception() # type: ignore
246
+ raise exc
247
247
 
248
248
  if pending:
249
249
  for awaitable in pending:
@@ -405,8 +405,8 @@ class PchkConnectionManager:
405
405
 
406
406
  def get_address_conn(
407
407
  self, addr: LcnAddr, request_serials: bool = True
408
- ) -> AbstractConnection:
409
- """Create and/or return an AbstractConnection to the given module or group."""
408
+ ) -> ModuleConnection | GroupConnection:
409
+ """Create and/or return a connection to the given module or group."""
410
410
  if addr.is_group:
411
411
  return self.get_group_conn(addr)
412
412
  return self.get_module_conn(addr, request_serials)
pypck/helpers.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Helper functions for pypck."""
2
2
 
3
3
  import asyncio
4
- from collections.abc import Awaitable
4
+ from collections.abc import Coroutine
5
5
  from typing import Any
6
6
 
7
7
 
@@ -30,9 +30,9 @@ class TaskRegistry:
30
30
  if task in self.tasks:
31
31
  self.tasks.remove(task)
32
32
 
33
- def create_task(self, coro: Awaitable[Any]) -> "asyncio.Task[None]":
33
+ def create_task(self, coro: Coroutine[Any, Any, Any]) -> "asyncio.Task[None]":
34
34
  """Create a task and store a reference in the task registry."""
35
- task = asyncio.create_task(coro) # type: ignore
35
+ task: asyncio.Task[Any] = asyncio.create_task(coro)
36
36
  task.add_done_callback(self.remove_task)
37
37
  self.tasks.append(task)
38
38
  return task
pypck/lcn_defs.py CHANGED
@@ -360,6 +360,44 @@ class Var(Enum):
360
360
  S0INPUT3 = auto()
361
361
  S0INPUT4 = auto() # LCN-BU4LJVarValue
362
362
 
363
+ @classmethod
364
+ def variables(cls) -> list[Var]:
365
+ """Return a list of all variable types."""
366
+ return [
367
+ cls.VAR1ORTVAR,
368
+ cls.VAR2ORR1VAR,
369
+ cls.VAR3ORR2VAR,
370
+ cls.VAR4,
371
+ cls.VAR5,
372
+ cls.VAR6,
373
+ cls.VAR7,
374
+ cls.VAR8,
375
+ cls.VAR9,
376
+ cls.VAR10,
377
+ cls.VAR11,
378
+ cls.VAR12,
379
+ ]
380
+
381
+ @classmethod
382
+ def set_points(cls) -> list[Var]:
383
+ """Return a list of all set-point variable types."""
384
+ return [cls.R1VARSETPOINT, cls.R2VARSETPOINT]
385
+
386
+ @classmethod
387
+ def thresholds(cls) -> list[list[Var]]:
388
+ """Return a list of all threshold variable types."""
389
+ return [
390
+ [cls.THRS1, cls.THRS2, cls.THRS3, cls.THRS4, cls.THRS5],
391
+ [cls.THRS2_1, cls.THRS2_2, cls.THRS2_3, cls.THRS2_4],
392
+ [cls.THRS3_1, cls.THRS3_2, cls.THRS3_3, cls.THRS3_4],
393
+ [cls.THRS4_1, cls.THRS4_2, cls.THRS4_3, cls.THRS4_4],
394
+ ]
395
+
396
+ @classmethod
397
+ def s0s(cls) -> list[Var]:
398
+ """Return a list of all S0-input variable types."""
399
+ return [cls.S0INPUT1, cls.S0INPUT2, cls.S0INPUT3, cls.S0INPUT4]
400
+
363
401
  @staticmethod
364
402
  def var_id_to_var(var_id: int) -> Var:
365
403
  """Translate a given id into a variable type.
@@ -369,9 +407,9 @@ class Var(Enum):
369
407
  :returns: The translated variable enum.
370
408
  :rtype: Var
371
409
  """
372
- if (var_id < 0) or (var_id >= len(Var.variables)): # type: ignore
410
+ if (var_id < 0) or (var_id >= len(Var.variables())):
373
411
  raise ValueError("Bad var_id.")
374
- return Var.variables[var_id] # type: ignore
412
+ return Var.variables()[var_id]
375
413
 
376
414
  @staticmethod
377
415
  def set_point_id_to_var(set_point_id: int) -> Var:
@@ -382,9 +420,9 @@ class Var(Enum):
382
420
  :return: The translated var
383
421
  :rtype: Var
384
422
  """
385
- if (set_point_id < 0) or (set_point_id >= len(Var.set_points)): # type: ignore
423
+ if (set_point_id < 0) or (set_point_id >= len(Var.set_points())):
386
424
  raise ValueError("Bad set_point_id.")
387
- return Var.set_points[set_point_id] # type: ignore
425
+ return Var.set_points()[set_point_id]
388
426
 
389
427
  @staticmethod
390
428
  def thrs_id_to_var(register_id: int, thrs_id: int) -> Var:
@@ -399,12 +437,12 @@ class Var(Enum):
399
437
  """
400
438
  if (
401
439
  (register_id < 0)
402
- or (register_id >= len(Var.thresholds)) # type: ignore
440
+ or (register_id >= len(Var.thresholds()))
403
441
  or (thrs_id < 0)
404
442
  or (thrs_id >= (5 if (register_id == 0) else 4))
405
443
  ):
406
444
  raise ValueError("Bad register_id and/or thrs_id.")
407
- return Var.thresholds[register_id][thrs_id] # type: ignore
445
+ return Var.thresholds()[register_id][thrs_id]
408
446
 
409
447
  @staticmethod
410
448
  def s0_id_to_var(s0_id: int) -> Var:
@@ -415,9 +453,9 @@ class Var(Enum):
415
453
  :return: The translated var
416
454
  :rtype: Var
417
455
  """
418
- if (s0_id < 0) or (s0_id >= len(Var.s0s)): # type: ignore
456
+ if (s0_id < 0) or (s0_id >= len(Var.s0s())):
419
457
  raise ValueError("Bad s0_id.")
420
- return Var.s0s[s0_id] # type: ignore
458
+ return Var.s0s()[s0_id]
421
459
 
422
460
  @staticmethod
423
461
  def to_var_id(var: Var) -> int:
@@ -658,42 +696,6 @@ class Var(Enum):
658
696
  return (not lock_state) and (software_serial < 0x170206)
659
697
 
660
698
 
661
- # Helper list to get var by numeric id.
662
- Var.variables = [ # type: ignore
663
- Var.VAR1ORTVAR,
664
- Var.VAR2ORR1VAR,
665
- Var.VAR3ORR2VAR,
666
- Var.VAR4,
667
- Var.VAR5,
668
- Var.VAR6,
669
- Var.VAR7,
670
- Var.VAR8,
671
- Var.VAR9,
672
- Var.VAR10,
673
- Var.VAR11,
674
- Var.VAR12,
675
- ]
676
-
677
- # Helper list to get set-point var by numeric id.
678
- Var.set_points = [Var.R1VARSETPOINT, Var.R2VARSETPOINT] # type: ignore
679
-
680
- # Helper list to get threshold var by numeric id.
681
- Var.thresholds = [ # type: ignore
682
- [Var.THRS1, Var.THRS2, Var.THRS3, Var.THRS4, Var.THRS5],
683
- [Var.THRS2_1, Var.THRS2_2, Var.THRS2_3, Var.THRS2_4],
684
- [Var.THRS3_1, Var.THRS3_2, Var.THRS3_3, Var.THRS3_4],
685
- [Var.THRS4_1, Var.THRS4_2, Var.THRS4_3, Var.THRS4_4],
686
- ]
687
-
688
- # Helper list to get S0-input var by numeric id.
689
- Var.s0s = [ # type: ignore
690
- Var.S0INPUT1,
691
- Var.S0INPUT2,
692
- Var.S0INPUT3,
693
- Var.S0INPUT4,
694
- ]
695
-
696
-
697
699
  class VarUnit(Enum):
698
700
  """Measurement units used with LCN variables."""
699
701
 
pypck/module.py CHANGED
@@ -174,19 +174,22 @@ class AbstractConnection:
174
174
  self.wants_ack, PckGenerator.rel_output(output_id, percent)
175
175
  )
176
176
 
177
- async def toggle_output(self, output_id: int, ramp: int) -> bool:
177
+ async def toggle_output(
178
+ self, output_id: int, ramp: int, to_memory: bool = False
179
+ ) -> bool:
178
180
  """Send a command that toggles a single output-port.
179
181
 
180
182
  Toggle mode: (on->off, off->on).
181
183
 
182
184
  :param int output_id: Output id 0..3
183
185
  :param int ramp: Ramp time in milliseconds
186
+ :param bool to_memory: If True, the dimming status is stored
184
187
 
185
188
  :returns: True if command was sent successfully, False otherwise
186
189
  :rtype: bool
187
190
  """
188
191
  return await self.send_command(
189
- self.wants_ack, PckGenerator.toggle_output(output_id, ramp)
192
+ self.wants_ack, PckGenerator.toggle_output(output_id, ramp, to_memory)
190
193
  )
191
194
 
192
195
  async def toggle_all_outputs(self, ramp: int) -> bool:
pypck/pck_commands.py CHANGED
@@ -471,19 +471,21 @@ class PckGenerator:
471
471
  return pck
472
472
 
473
473
  @staticmethod
474
- def toggle_output(output_id: int, ramp: int) -> str:
474
+ def toggle_output(output_id: int, ramp: int, to_memory: bool = False) -> str:
475
475
  """Generate a command that toggles a single output-port.
476
476
 
477
477
  Toggle mode: (on->off, off->on).
478
478
 
479
479
  :param int output_id: Output id 0..3
480
480
  :param int ramp: Ramp value
481
+ :param bool to_memory: If True, the dimming status is stored
482
+
481
483
  :return: The PCK command (without address header) as text
482
484
  :rtype: str
483
485
  """
484
486
  if (output_id < 0) or (output_id > 3):
485
487
  raise ValueError("Invalid output_id.")
486
- return f"A{output_id + 1}TA{ramp:03d}"
488
+ return f"A{output_id + 1}{'MT' if to_memory else 'TA'}{ramp:03d}"
487
489
 
488
490
  @staticmethod
489
491
  def toggle_all_outputs(ramp: int) -> str:
pypck/request_handlers.py CHANGED
@@ -660,6 +660,7 @@ class StatusRequestsHandler:
660
660
  async def activate_all(self, activate_s0: bool = False) -> None:
661
661
  """Activate all status requests."""
662
662
  await self.addr_conn.conn.segment_scan_completed_event.wait()
663
+ var_s0s = lcn_defs.Var.s0s()
663
664
  for item in (
664
665
  list(lcn_defs.OutputPort)
665
666
  + list(lcn_defs.RelayPort)
@@ -673,7 +674,7 @@ class StatusRequestsHandler:
673
674
  if (
674
675
  (not activate_s0)
675
676
  and isinstance(item, lcn_defs.Var)
676
- and (item in lcn_defs.Var.s0s) # type: ignore
677
+ and (item in var_s0s)
677
678
  ):
678
679
  continue
679
680
  await self.activate(item)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypck
3
- Version: 0.8.8
3
+ Version: 0.8.10
4
4
  Summary: LCN-PCK library
5
5
  Home-page: https://github.com/alengwenus/pypck
6
6
  Author-email: Andre Lengwenus <alengwenus@gmail.com>
@@ -0,0 +1,15 @@
1
+ pypck/__init__.py,sha256=vjI-MSv-ght8Y_tcKPXYMjL-FGlHX6Z2ofrUBrz8g4U,317
2
+ pypck/connection.py,sha256=M9AGdq46UjrOyz0V_tZX1IHqGg5Mb3SKs2tzy4wQQhg,24379
3
+ pypck/helpers.py,sha256=_5doqIsSRpqdQNPIUsjFh813xKGuMuEFY6sNGobJGIk,1280
4
+ pypck/inputs.py,sha256=cjhvYKPr5QHw7Rjfkkg8LPbP8ohq_-z_Tvk51Rkx0aY,45828
5
+ pypck/lcn_addr.py,sha256=N2Od8KuANOglqKjf596hJVH1SRcG7MhESKA5YYlDnbw,1946
6
+ pypck/lcn_defs.py,sha256=e2KqD6r-JUwp20BcTymbpjsX16zjOihGKDqreWDsrwo,41951
7
+ pypck/module.py,sha256=bRXIVQjaBr6Gfs_xYMMDeTZAle86M-nm6YfzyTjs7kA,38476
8
+ pypck/pck_commands.py,sha256=bkb3q49s4PVY6UNR0B6S31oU7aSaEbpPl3rj0eGxTQU,50380
9
+ pypck/request_handlers.py,sha256=Ft9teTysw-tc9gMdXgh1en-e3MxXmIsiqv5ZQDI_b9E,25234
10
+ pypck/timeout_retry.py,sha256=FzeoyhmA4Tj13wR4kGXUwH8HyXnZ1RQOAYY9sSbz6rw,3859
11
+ pypck-0.8.10.dist-info/licenses/LICENSE,sha256=iYB6zyMJvShfAzQE7nhYFgLzzZuBmhasLw5fYP9KRz4,1023
12
+ pypck-0.8.10.dist-info/METADATA,sha256=1Vkcj-dIBNtp_BJiHDJ_WB6hMwkRQTrHzEHm8ecnWTI,5604
13
+ pypck-0.8.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ pypck-0.8.10.dist-info/top_level.txt,sha256=59ried49iFueDa5mQ_5BGVZcESjjzi4MZZKLcganvQA,6
15
+ pypck-0.8.10.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- pypck/__init__.py,sha256=vjI-MSv-ght8Y_tcKPXYMjL-FGlHX6Z2ofrUBrz8g4U,317
2
- pypck/connection.py,sha256=MP2150GTdPDJ-xC93doCYEIbv4Xkt8-84ArXoe31LSY,24426
3
- pypck/helpers.py,sha256=hEGId1pQ4wOJgIwNKDx17qKBlxvNxvspSrI0gSY3wCQ,1267
4
- pypck/inputs.py,sha256=cjhvYKPr5QHw7Rjfkkg8LPbP8ohq_-z_Tvk51Rkx0aY,45828
5
- pypck/lcn_addr.py,sha256=N2Od8KuANOglqKjf596hJVH1SRcG7MhESKA5YYlDnbw,1946
6
- pypck/lcn_defs.py,sha256=UffOX1s2856MXRgc3dv6SzSPGze4IiSk_sT-PpWTva8,41741
7
- pypck/module.py,sha256=SBKfblaGYvYBp-gzvnn606W6eJy-ICTGzA7KxNvllgk,38349
8
- pypck/pck_commands.py,sha256=uG57j-Ju9JzKeglYYxk5hiBjFA9aSsSDSzNhZ2b1TWA,50250
9
- pypck/request_handlers.py,sha256=mGwM4_jpVpTxTQ7kgkEa_PYgliTm-omtzEf3LcIdpD8,25222
10
- pypck/timeout_retry.py,sha256=FzeoyhmA4Tj13wR4kGXUwH8HyXnZ1RQOAYY9sSbz6rw,3859
11
- pypck-0.8.8.dist-info/licenses/LICENSE,sha256=iYB6zyMJvShfAzQE7nhYFgLzzZuBmhasLw5fYP9KRz4,1023
12
- pypck-0.8.8.dist-info/METADATA,sha256=LrK3YHB8d5iIj6wbHj_Kr7cDhgiJyQVsJGRcm_tzPJM,5603
13
- pypck-0.8.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- pypck-0.8.8.dist-info/top_level.txt,sha256=59ried49iFueDa5mQ_5BGVZcESjjzi4MZZKLcganvQA,6
15
- pypck-0.8.8.dist-info/RECORD,,
File without changes