1- """
2- Module for KNX Telegrams.
3-
4- The telegram class is the lightweight data transfer object between
5-
6- * business logic (Lights, Covers, etc) and
7- * underlying KNX/IP abstraction (CEMIHandler).
8-
9- It contains
10-
11- * the group address (e.g. GroupAddress("1/2/3"))
12- * the direction (Incoming or Outgoing)
13- * and the payload (e.g. GroupValueWrite(DPTBinary(False)))
14- * the source address (e.g. IndividualAddress("1.2.3"))
15- * the TPCI (Transport Layer Control Information) (e.g. TDataGroup())
16- """
1+ """Module for KNX Telegrams."""
172
183from __future__ import annotations
194
@@ -51,16 +36,46 @@ def __str__(self) -> str:
5136
5237@dataclass (slots = True )
5338class Telegram :
54- """Class for KNX telegrams."""
39+ """
40+ Data transfer object for KNX telegrams.
41+
42+ Represents a message exchanged on the KNX bus between the business logic
43+ (Devices, Management, etc.) and the underlying KNX/IP abstraction layer.
44+
45+ Attributes:
46+ destination_address: Target GroupAddress, IndividualAddress, or
47+ InternalGroupAddress.
48+ direction: Communication direction (INCOMING or OUTGOING).
49+ payload: APCi payload containing the actual data (e.g., GroupValueWrite,
50+ GroupValueResponse). None for control information only telegrams.
51+ source_address: IndividualAddress of the sender. When default of 0.0.0 is
52+ used, it will be set automatically when sent.
53+ tpci: Transport Layer Control Information (TDataBroadcast, TDataGroup, or
54+ TDataIndividual). If not provided, it will be automatically inferred
55+ based on destination_address type.
56+ decoded_data: Optional decoded version of the payload including the
57+ transcoder class and decoded value. Set externally by GroupAddressDPT
58+ for convenience when the payload has already been decoded.
59+ data_secure: Flag indicating if the telegram was sent or received as
60+ DataSecure. Set externally by CEMIHandler. None if not yet processed.
61+
62+ """
5563
5664 destination_address : GroupAddress | IndividualAddress | InternalGroupAddress
5765 direction : TelegramDirection = TelegramDirection .OUTGOING
5866 payload : APCI | None = None
5967 source_address : IndividualAddress = field (
6068 default_factory = lambda : IndividualAddress (0 )
6169 )
62- tpci : TPCI = None # type: ignore[assignment] # set in __post_init__
63- decoded_data : TelegramDecodedData | None = None
70+ tpci : TPCI = None # type: ignore[assignment] # set by initializer or in __post_init__
71+ # set by GroupAddressDPT
72+ decoded_data : TelegramDecodedData | None = field (
73+ init = False , default = None , compare = False , hash = False
74+ )
75+ # flag if telegram was sent or received as DataSecure, set by CEMIHandler
76+ data_secure : bool | None = field (
77+ init = False , default = None , compare = False , hash = False
78+ )
6479
6580 def __post_init__ (self ) -> None :
6681 """Initialize Telegram class."""
@@ -75,17 +90,6 @@ def __post_init__(self) -> None:
7590 else : # InternalGroupAddress
7691 self .tpci = TDataGroup ()
7792
78- def __eq__ (self , other : object ) -> bool :
79- """Equal operator. Omit decoded_data for comparison."""
80- return (
81- isinstance (other , Telegram )
82- and self .destination_address == other .destination_address
83- and self .direction == other .direction
84- and self .payload == other .payload
85- and self .source_address == other .source_address
86- and self .tpci == other .tpci
87- )
88-
8993 def __str__ (self ) -> str :
9094 """Return object as readable string."""
9195 data = f'payload="{ self .payload } "' if self .payload else f'tpci="{ self .tpci } "'
0 commit comments