crystalfontz.dbus.domain
DBus uses a collection of types that are documented in the specification. The base types are more fine-grained than Python's base types, but are non-nullable - ie, there's no None type in DBus. Moreover, its collection types don't map cleanly to arbitrary Python class instances - rather, you get basic structs (which correspond to Python tuples) and arrays (which correspond to Python lists). This means that, when interacting with the DBus client, you will need to work with types other than the domain objects used in the standard crystalfontz client.
To facilitate this, crystalfontz includes a submodule for mapping between domain objects and DBus types, at crystalfontz.dbus.domain. This module exports both aliases for the types used by the DBus interface, and mapper classes for packing and unpacking domain objects to and from DBus types.
Represent entities in the crystalfontz domain model with dbus-compatible types, and map between the crystalfontz and dbus domains.
While these classes don't all implement the same protocols, they do follow a number of important conventions.
Naming Conventions
In general classes corresponding to entities share their names, but with a postfix naming convention.
Dbus types corresponding to entities in the crystalfontz domain have T appended
to them. For instance, the dbus type corresponding to Optional[bytes] is OptBytesT,
which corresponds to the "ay" dbus type signature. This applies to more complex
entities as well - for instance, the dbus type corresponding to the Versions response
is VersionsT.
Mappers - classes that map between entities and dbus types - have M appended to
their names. For intance, the mapper for Optional[bytes] and OptBytesT is called
OptBytesM.
pack methods and none properties
Mappers which support it have a pack class method, which takes objects from the
crystalfontz domain and converts them into dbus data types. For instance, OptBytesM
packs an Optional[bytes] value into a OptBytesT.
Additionally, mappers representing optional data have a property called none,
which contains the value that the dbus client canonically interprets as None.
For instance, TimeoutM.none is equal to -1.0. Note that, in this case,
the dbus client treats any value less than 0 as None.
As a user, you would typically use these APIs when constructing arguments for the
dbus client. For example, if you were to call dbus_client.ping, it would look like
this:
pong: PongT = await dbus_client.ping(
b"Hello world!", TimeoutM.pack(timeout), RetryTimesM.pack(retry_times)
)
unpack methods
Dbus client methods will not only be called with dbus-compatible types, but
will return dbus-compatible types as well. Sometimes these are sensible - in fact,
most methods return None. However, for non-trivial response types, you will likely
want to unpack them back into the crystalfontz domain. For example, the ping
command returns a PongT, and you will probably want to unpack it into a Pong
object:
print(PongM.unpack(pong).response)
ConfigM
Map Config to and from ConfigT
(Tuple[Optional[str], str, str, str, str, int, float, int]).
Source code in crystalfontz/dbus/domain/config.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
pack(config)
staticmethod
Pack Config to ConfigT.
Source code in crystalfontz/dbus/domain/config.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
unpack(config)
staticmethod
Unpack ConfigT to Config.
Source code in crystalfontz/dbus/domain/config.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
CursorStyleM
Map CursorStyle to and from CursorStyleT (int).
Source code in crystalfontz/dbus/domain/cursor.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
pack(style)
staticmethod
Pack CursorStyle to CursorStyleT.
Source code in crystalfontz/dbus/domain/cursor.py
17 18 19 20 21 22 23 | |
unpack(style)
staticmethod
Unpack CursorStyleT to CursorStyle.
Source code in crystalfontz/dbus/domain/cursor.py
25 26 27 28 29 30 31 | |
DowDeviceInformationM
Map DowDeviceInformation to and from DowDeviceInformationT
(Tuple[int, int]).
Source code in crystalfontz/dbus/domain/response.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
unpack(info)
staticmethod
Unpack DowDeviceInformation to DowDeviceInformationT.
Source code in crystalfontz/dbus/domain/response.py
157 158 159 160 161 162 163 164 | |
DowTransactionResultM
Map DowTransactionResult to and from DowTransactionResultT
(Tuple[int, bytes, int]).
Source code in crystalfontz/dbus/domain/response.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
unpack(res)
staticmethod
Unpack DowTransactionResultT to DowTransactionResult.
Source code in crystalfontz/dbus/domain/response.py
182 183 184 185 186 187 188 189 | |
GpioReadM
Map GpioRead to and from GpioReadT
(Tuple[int, Tuple[bool, bool, bool], int, int]).
Source code in crystalfontz/dbus/domain/response.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
unpack(gpio_read)
staticmethod
Unpack GpioReadT to GpioRead.
Source code in crystalfontz/dbus/domain/response.py
237 238 239 240 241 242 243 244 245 246 247 248 249 | |
KeyActivityReportM
Map KeyActivityReport to and from KeyActivityReportT
Source code in crystalfontz/dbus/domain/response.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
KeypadBrightnessM
Bases: OptFloatM
Map Optional[float] to and from KeypadBrightnessT (float).
KeypadBrightnessM is an alias for OptFloatM.
Source code in crystalfontz/dbus/domain/keys.py
91 92 93 94 95 96 97 98 | |
KeypadPolledM
Map KeypadPolled to and from KeypadPolledT
(Tuple[KeyStateT, KeyStateT, KeyStateT, KeyStateT, KeyStateT, KeyStateT],
where KeyStateT = Tuple[bool, bool, bool]).
Source code in crystalfontz/dbus/domain/response.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
unpack(polled)
staticmethod
Unpack KeypadPolledT to KeypadPolled.
Source code in crystalfontz/dbus/domain/response.py
208 209 210 211 212 213 214 | |
LcdMemoryM
Map LcdMemory to and from LcdMemoryT (Tuple[int, bytes]).
Source code in crystalfontz/dbus/domain/response.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
unpack(obj)
staticmethod
Unpack LcdMemoryT to LcdMemory.
Source code in crystalfontz/dbus/domain/response.py
132 133 134 135 136 137 138 139 | |
LcdRegisterM
Map LcdRegister to and from LcdRegisterT (bool).
Source code in crystalfontz/dbus/domain/lcd.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
OptBytesM
Map Optional[bytes] to and from OptBytesT (bytes).
None values are represented by an empty bytestring.
Source code in crystalfontz/dbus/domain/base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
pack(buff)
classmethod
Pack Optional[bytes] to OptBytesT.
Source code in crystalfontz/dbus/domain/base.py
175 176 177 178 179 180 181 182 183 | |
unpack(buff)
staticmethod
Unpack OptBytesT to Optional[bytes].
Source code in crystalfontz/dbus/domain/base.py
185 186 187 188 189 190 191 192 193 | |
OptFloatM
Map Optional[float] to and from OptFloatT (float), where float values
are expected to be positive.
None values are represented by negative values, namely -1.0.
Source code in crystalfontz/dbus/domain/base.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
pack(t)
classmethod
Pack Optional[float] to OptFloatT.
Source code in crystalfontz/dbus/domain/base.py
76 77 78 79 80 81 82 | |
unpack(t)
staticmethod
Unpack OptFloatT to Optional[float].
Source code in crystalfontz/dbus/domain/base.py
84 85 86 87 88 89 90 | |
OptGpioSettingsM
Map Optional[GpioSettings] to and from OptGpioSettingsT (int).
Optional GPIO settings are represented by a UINT16, where values higher than 0xFF are treated as None. When GPIO settings are defined, the integer value will be the same as with required GPIO settings.
Source code in crystalfontz/dbus/domain/gpio.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
OptStrM
Map Optional[str] to and from StrT (str).
None values are represented by an empty string.
Source code in crystalfontz/dbus/domain/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
pack(string)
classmethod
Pack Optional[str] to OptStrT.
Source code in crystalfontz/dbus/domain/base.py
106 107 108 109 110 111 112 | |
unpack(string)
classmethod
Unpack OptStrT to Optional[str].
Source code in crystalfontz/dbus/domain/base.py
114 115 116 117 118 119 120 | |
PongM
Map Pong to and from PongT (bytes).
Source code in crystalfontz/dbus/domain/response.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
pack(pong)
staticmethod
Pack Pong to PongT.
Source code in crystalfontz/dbus/domain/response.py
55 56 57 58 59 60 61 | |
unpack(pong)
staticmethod
Unpack PongT to Pong.
Source code in crystalfontz/dbus/domain/response.py
63 64 65 66 67 68 69 | |
RetryTimesM
Bases: OptIntM
Map Optional[int] to and from RetryTimesT (int).
RetryTimesM is an alias for OptIntM.
Source code in crystalfontz/dbus/domain/base.py
234 235 236 237 238 239 240 241 242 | |
TemperatureDisplayItemM
Map TemperatureDisplayItem to and from TemperatureDisplayItemT
(Tuple[int, int, int, int, bool]).
Source code in crystalfontz/dbus/domain/temperature.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
pack(item)
staticmethod
Pack TemperatureDisplayItem to TemperatureDisplayItemT.
Source code in crystalfontz/dbus/domain/temperature.py
53 54 55 56 57 58 59 60 61 62 63 64 65 | |
unpack(item)
staticmethod
Unpack TemperatureDisplayItemT to TemperatureDisplayItem.
Source code in crystalfontz/dbus/domain/temperature.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
TemperatureReportM
Map TemperatureReport to and from KeyActivityReportT
Source code in crystalfontz/dbus/domain/response.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
TimeoutM
Bases: OptFloatM
Map Optional[float] to and from TimeoutT (float).
TimeoutM is an alias for OptFloatM.
Source code in crystalfontz/dbus/domain/base.py
220 221 222 223 224 225 226 227 228 | |
VersionsM
Map Versions to and from VersionsT (Tuple[str, str, str]).
Source code in crystalfontz/dbus/domain/response.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
unpack(versions)
staticmethod
Unpack VersionsT to Versions.
Source code in crystalfontz/dbus/domain/response.py
86 87 88 89 90 91 92 | |