tinkerforge-async 1.6.2__tar.gz → 1.8.0__tar.gz

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.
Files changed (43) hide show
  1. {tinkerforge_async-1.6.2/tinkerforge_async.egg-info → tinkerforge_async-1.8.0}/PKG-INFO +5 -5
  2. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/README.md +1 -0
  3. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/pyproject.toml +4 -8
  4. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/_version.py +1 -1
  5. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_barometer_v2.py +1 -1
  6. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_humidity_v2.py +2 -2
  7. tinkerforge_async-1.8.0/tinkerforge_async/bricklet_industrial_dual_0_20ma_v2.py +476 -0
  8. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_industrial_dual_analog_in_v2.py +2 -2
  9. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_thermocouple_v2.py +2 -2
  10. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/device_factory.py +2 -0
  11. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/devices.py +7 -1
  12. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0/tinkerforge_async.egg-info}/PKG-INFO +5 -5
  13. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async.egg-info/SOURCES.txt +1 -0
  14. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async.egg-info/requires.txt +0 -3
  15. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/LICENSE +0 -0
  16. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/setup.cfg +0 -0
  17. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/setup.py +0 -0
  18. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/__init__.py +0 -0
  19. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/async_event_bus.py +0 -0
  20. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/brick_master.py +0 -0
  21. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_ambient_light_v2.py +0 -0
  22. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_ambient_light_v3.py +0 -0
  23. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_analog_in.py +0 -0
  24. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_barometer.py +0 -0
  25. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_humidity.py +0 -0
  26. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_industrial_ptc.py +0 -0
  27. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_io16.py +0 -0
  28. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_io4_v2.py +0 -0
  29. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_isolator.py +0 -0
  30. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_moisture.py +0 -0
  31. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_motion_detector_v2.py +0 -0
  32. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_ptc.py +0 -0
  33. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_ptc_v2.py +0 -0
  34. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_rs232_v2.py +0 -0
  35. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_segment_display_4x7.py +0 -0
  36. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_segment_display_4x7_v2.py +0 -0
  37. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_temperature.py +0 -0
  38. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/bricklet_temperature_v2.py +0 -0
  39. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/helper.py +0 -0
  40. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/ip_connection.py +0 -0
  41. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async/ip_connection_helper.py +0 -0
  42. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async.egg-info/dependency_links.txt +0 -0
  43. {tinkerforge_async-1.6.2 → tinkerforge_async-1.8.0}/tinkerforge_async.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinkerforge-async
3
- Version: 1.6.2
3
+ Version: 1.8.0
4
4
  Summary: Python3 AsyncIO Tinkerforge driver
5
5
  Author-email: Patrick Baus <patrick.baus@physik.tu-darmstadt.de>
6
6
  License-Expression: GPL-3.0-or-later
@@ -9,11 +9,11 @@ Project-URL: Bug Tracker, https://github.com/PatrickBaus/tinkerforge_async/issue
9
9
  Project-URL: Download, https://github.com/PatrickBaus/tinkerforge_async/releases
10
10
  Keywords: IoT,Tinkerforge,API
11
11
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
12
  Classifier: Programming Language :: Python :: 3.11
15
13
  Classifier: Programming Language :: Python :: 3.12
16
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
17
  Classifier: Development Status :: 5 - Production/Stable
18
18
  Classifier: Operating System :: OS Independent
19
19
  Classifier: Intended Audience :: Developers
@@ -21,10 +21,9 @@ Classifier: Intended Audience :: Science/Research
21
21
  Classifier: Natural Language :: English
22
22
  Classifier: Topic :: Home Automation
23
23
  Classifier: Topic :: Scientific/Engineering
24
- Requires-Python: >=3.9
24
+ Requires-Python: >=3.11
25
25
  Description-Content-Type: text/markdown
26
26
  License-File: LICENSE
27
- Requires-Dist: typing-extensions; python_version < "3.11"
28
27
  Provides-Extra: dev
29
28
  Requires-Dist: black; extra == "dev"
30
29
  Requires-Dist: build; extra == "dev"
@@ -71,6 +70,7 @@ The library is fully type-hinted.
71
70
  | [Barometer 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Barometer_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
72
71
  | [Humidity](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity.html) |:heavy_check_mark:|:heavy_check_mark:|
73
72
  | [Humidity 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
73
+ | [Industrial Dual 0-20mA 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_020mA_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
74
74
  | [Industrial Dual Analog In 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_Analog_In_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
75
75
  | [Industrial PTC](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_PTC.html) |:heavy_check_mark:|:heavy_check_mark:|
76
76
  | [IO-4 2.0](https://www.tinkerforge.com/de/doc/Hardware/Bricklets/IO4_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
@@ -25,6 +25,7 @@ The library is fully type-hinted.
25
25
  | [Barometer 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Barometer_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
26
26
  | [Humidity](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity.html) |:heavy_check_mark:|:heavy_check_mark:|
27
27
  | [Humidity 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
28
+ | [Industrial Dual 0-20mA 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_020mA_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
28
29
  | [Industrial Dual Analog In 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_Analog_In_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
29
30
  | [Industrial PTC](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_PTC.html) |:heavy_check_mark:|:heavy_check_mark:|
30
31
  | [IO-4 2.0](https://www.tinkerforge.com/de/doc/Hardware/Bricklets/IO4_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
@@ -9,14 +9,14 @@ license = "GPL-3.0-or-later"
9
9
  license-files = [
10
10
  "LICENSE",
11
11
  ]
12
- requires-python = ">=3.9"
12
+ requires-python = ">=3.11"
13
13
  classifiers = [
14
14
  "Programming Language :: Python :: 3",
15
- "Programming Language :: Python :: 3.9",
16
- "Programming Language :: Python :: 3.10",
17
15
  "Programming Language :: Python :: 3.11",
18
16
  "Programming Language :: Python :: 3.12",
19
17
  "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ "Programming Language :: Python :: 3.15",
20
20
  "Development Status :: 5 - Production/Stable",
21
21
  "Operating System :: OS Independent",
22
22
  "Intended Audience :: Developers",
@@ -26,9 +26,6 @@ classifiers = [
26
26
  "Topic :: Scientific/Engineering",
27
27
  ]
28
28
  keywords = ["IoT", "Tinkerforge", "API"]
29
- dependencies = [
30
- "typing-extensions; python_version <'3.11'",
31
- ]
32
29
  dynamic = ["version"]
33
30
 
34
31
  [project.urls]
@@ -74,8 +71,7 @@ markers = [
74
71
 
75
72
  [build-system]
76
73
  requires = [
77
- "setuptools>=77.0",
78
- "typing-extensions; python_version <'3.11'",
74
+ "setuptools>=84.0",
79
75
  ]
80
76
  build-backend = "setuptools.build_meta"
81
77
 
@@ -1,2 +1,2 @@
1
1
  # pylint: disable=missing-module-docstring
2
- __version__ = "1.6.2"
2
+ __version__ = "1.8.0"
@@ -427,7 +427,7 @@ class BrickletBarometerV2(BrickletWithMCU): # pylint: disable=too-many-public-m
427
427
  Returns the callback configuration as set by :func:`Set Temperature Callback Configuration`.
428
428
  """
429
429
  _, payload = await self.ipcon.send_request(
430
- device=self, function_id=FunctionID.GET_ALTITUDE_CALLBACK_CONFIGURATION, response_expected=True
430
+ device=self, function_id=FunctionID.GET_TEMPERATURE_CALLBACK_CONFIGURATION, response_expected=True
431
431
  )
432
432
  period, value_has_to_change, option, minimum, maximum = unpack_payload(payload, "I ! c i i")
433
433
  option = Threshold(option)
@@ -322,7 +322,7 @@ class BrickletHumidityV2(BrickletWithMCU):
322
322
  self.__si_to_temperature_sensor(minimum),
323
323
  self.__si_to_temperature_sensor(maximum),
324
324
  ),
325
- "I ! c H H",
325
+ "I ! c h h",
326
326
  ),
327
327
  response_expected=response_expected,
328
328
  )
@@ -334,7 +334,7 @@ class BrickletHumidityV2(BrickletWithMCU):
334
334
  _, payload = await self.ipcon.send_request(
335
335
  device=self, function_id=FunctionID.GET_TEMPERATURE_CALLBACK_CONFIGURATION, response_expected=True
336
336
  )
337
- period, value_has_to_change, option, minimum, maximum = unpack_payload(payload, "I ! c H H")
337
+ period, value_has_to_change, option, minimum, maximum = unpack_payload(payload, "I ! c h h")
338
338
  option = Threshold(option)
339
339
  minimum, maximum = self.__temperature_sensor_to_si(minimum), self.__temperature_sensor_to_si(maximum)
340
340
  return AdvancedCallbackConfiguration(period, value_has_to_change, option, minimum, maximum)
@@ -0,0 +1,476 @@
1
+ """
2
+ Module for the Tinkerforge Industrial Dual 0-20mA Bricklet 2.0
3
+ (https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_020mA_V2.html) implemented using Python
4
+ asyncio. It does the low-level communication with the Tinkerforge ip connection and also handles conversion of raw
5
+ units to SI units.
6
+ """
7
+
8
+ # pylint: disable=duplicate-code # Many sensors of different generations have a similar API
9
+ from __future__ import annotations
10
+
11
+ from decimal import Decimal
12
+ from enum import Enum, unique
13
+ from typing import TYPE_CHECKING, AsyncGenerator, NamedTuple
14
+
15
+ from .devices import (
16
+ AdvancedCallbackConfiguration,
17
+ BrickletWithMCU,
18
+ DeviceIdentifier,
19
+ Event,
20
+ LedConfig,
21
+ )
22
+ from .devices import ThresholdOption as Threshold
23
+ from .devices import (
24
+ _FunctionID,
25
+ )
26
+ from .ip_connection_helper import pack_payload, unpack_payload
27
+
28
+ if TYPE_CHECKING:
29
+ from .ip_connection import IPConnectionAsync
30
+
31
+
32
+ @unique
33
+ class CallbackID(Enum):
34
+ """
35
+ The callbacks available to this bricklet
36
+ """
37
+
38
+ CURRENT = 4
39
+
40
+
41
+ _CallbackID = CallbackID
42
+
43
+
44
+ @unique
45
+ class FunctionID(_FunctionID):
46
+ """
47
+ The function calls available to this bricklet
48
+ """
49
+
50
+ GET_CURRENT = 1
51
+ SET_CURRENT_CALLBACK_CONFIGURATION = 2
52
+ GET_CURRENT_CALLBACK_CONFIGURATION = 3
53
+ SET_SAMPLE_RATE = 5
54
+ GET_SAMPLE_RATE = 6
55
+ SET_GAIN = 7
56
+ GET_GAIN = 8
57
+ SET_CHANNEL_LED_CONFIG = 9
58
+ GET_CHANNEL_LED_CONFIG = 10
59
+ SET_CHANNEL_LED_STATUS_CONFIG = 11
60
+ GET_CHANNEL_LED_STATUS_CONFIG = 12
61
+
62
+
63
+ @unique
64
+ class ChannelLedStatusConfig(Enum):
65
+ """
66
+ Defines the LED brightness when LedConfig.SHOW_STATUS
67
+ """
68
+
69
+ THRESHOLD = 0
70
+ INTENSITY = 1
71
+
72
+
73
+ _ChannelLedStatusConfig = ChannelLedStatusConfig # We need the alias for MyPy type hinting
74
+
75
+
76
+ @unique
77
+ class SamplingRate(Enum):
78
+ """
79
+ Defines the sampling rate of the ADC. The resolution of the ADC depends on the sampling rate: 12 bit at 240 SPS,
80
+ 14 bit at 60 SPS, 16 bit at 15 SPS and 18 bit at 4 SPS.
81
+ """
82
+
83
+ RATE_240_SPS = 0
84
+ RATE_60_SPS = 1
85
+ RATE_15_SPS = 2
86
+ RATE_4_SPS = 3
87
+
88
+
89
+ _SamplingRate = SamplingRate # We need the alias for MyPy type hinting
90
+
91
+
92
+ @unique
93
+ class Gain(Enum):
94
+ """
95
+ Defines the gain of the ADC
96
+ """
97
+
98
+ GAIN_1X = 0
99
+ GAIN_2X = 1
100
+ GAIN_4X = 2
101
+ GAIN_8X = 3
102
+
103
+
104
+ _Gain = Gain # We need the alias for MyPy type hinting
105
+
106
+
107
+ class GetChannelLEDStatusConfig(NamedTuple):
108
+ minimum: Decimal
109
+ maximum: Decimal
110
+ config: ChannelLedStatusConfig
111
+
112
+
113
+ class BrickletIndustrialDual020mAV2(BrickletWithMCU):
114
+ """
115
+ Measures two currents between 0mA and 22.5mA (IEC 60381-1 compatible, so 4-20mA sensors work as well) with up to
116
+ 18bit resolution each. All currents are returned in A.
117
+ """
118
+
119
+ DEVICE_IDENTIFIER = DeviceIdentifier.BRICKLET_INDUSTRIAL_DUAL_0_20MA_V2
120
+ DEVICE_DISPLAY_NAME = "Industrial Dual 0-20mA Bricklet 2.0"
121
+
122
+ # Convenience imports, so that the user does not need to additionally import them
123
+ CallbackID = CallbackID
124
+ FunctionID = FunctionID
125
+ ThresholdOption = Threshold
126
+ ChannelLedConfig = LedConfig
127
+ ChannelLedStatusConfig = ChannelLedStatusConfig
128
+ SamplingRate = SamplingRate
129
+ Gain = Gain
130
+
131
+ CALLBACK_FORMATS = {
132
+ CallbackID.CURRENT: "B i",
133
+ }
134
+
135
+ SID_TO_CALLBACK = {
136
+ 0: (CallbackID.CURRENT,),
137
+ 1: (CallbackID.CURRENT,),
138
+ }
139
+
140
+ def __init__(self, uid: int, ipcon: IPConnectionAsync) -> None:
141
+ """
142
+ Creates an object with the unique device ID *uid* and adds it to the IP connection *ipcon*.
143
+ """
144
+ super().__init__(self.DEVICE_DISPLAY_NAME, uid, ipcon)
145
+
146
+ self.api_version = (2, 0, 0)
147
+
148
+ async def get_value(self, sid: int) -> Decimal:
149
+ assert sid in (0, 1)
150
+
151
+ return await self.get_current(sid)
152
+
153
+ async def set_callback_configuration( # pylint: disable=too-many-arguments,too-many-positional-arguments
154
+ self,
155
+ sid: int,
156
+ period: int = 0,
157
+ value_has_to_change: bool = False,
158
+ option: Threshold | str = Threshold.OFF,
159
+ minimum: float | Decimal | None = None,
160
+ maximum: float | Decimal | None = None,
161
+ response_expected: bool = True,
162
+ ) -> None:
163
+ minimum = 0 if minimum is None else minimum
164
+ maximum = 0 if maximum is None else maximum
165
+
166
+ assert sid in (0, 1)
167
+
168
+ await self.set_current_callback_configuration(
169
+ sid, period, value_has_to_change, option, minimum, maximum, response_expected
170
+ )
171
+
172
+ async def get_callback_configuration(self, sid: int) -> AdvancedCallbackConfiguration:
173
+ assert sid in (0, 1)
174
+
175
+ return await self.get_current_callback_configuration(sid)
176
+
177
+ async def get_current(self, channel: int) -> Decimal:
178
+ """
179
+ Returns the current of the specified channel in A.
180
+
181
+ It is possible to detect if an IEC 60381-1 compatible sensor is connected and if it works probably.
182
+
183
+ If the returned current is below 4mA, there is likely no sensor connected or the connected sensor is defective.
184
+ If the returned current is over 20mA, there might be a short circuit or the sensor is defective.
185
+
186
+ If you want to get the value periodically, it is recommended to use the :cb:`Current` callback. You can set the
187
+ callback configuration with :func:`Set Current Callback Configuration`.
188
+ """
189
+ assert channel in (0, 1)
190
+
191
+ _, payload = await self.ipcon.send_request(
192
+ device=self,
193
+ function_id=FunctionID.GET_CURRENT,
194
+ data=pack_payload((int(channel),), "B"),
195
+ response_expected=True,
196
+ )
197
+ return self.__value_to_si(unpack_payload(payload, "i"))
198
+
199
+ async def set_current_callback_configuration( # pylint: disable=too-many-arguments,too-many-positional-arguments
200
+ self,
201
+ channel: int,
202
+ period: int = 0,
203
+ value_has_to_change: bool = False,
204
+ option: Threshold | str = Threshold.OFF,
205
+ minimum: float | Decimal = 0,
206
+ maximum: float | Decimal = 0,
207
+ response_expected: bool = True,
208
+ ) -> None:
209
+ """
210
+ The period is the period with which the :cb:`Current` callback is triggered periodically. A value of 0 turns
211
+ the callback off.
212
+
213
+ If the `value has to change`-parameter is set to true, the callback is only triggered after the value has
214
+ changed. If the value didn't change within the period, the callback is triggered immediately on change.
215
+
216
+ If it is set to false, the callback is continuously triggered with the period, independent of the value.
217
+
218
+ It is furthermore possible to constrain the callback with thresholds.
219
+
220
+ The `option`-parameter together with min/max sets a threshold for the :cb:`Current` callback. The thresholds
221
+ are given in A.
222
+
223
+ The following options are possible:
224
+
225
+ .. csv-table::
226
+ :header: "Option", "Description"
227
+ :widths: 10, 100
228
+
229
+ "'x'", "Threshold is turned off"
230
+ "'o'", "Threshold is triggered when the value is *outside* the min and max values"
231
+ "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
232
+ "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
233
+ "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
234
+
235
+ If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
236
+ """
237
+ assert channel in (0, 1)
238
+ option = Threshold(option)
239
+ assert period >= 0
240
+
241
+ await self.ipcon.send_request(
242
+ device=self,
243
+ function_id=FunctionID.SET_CURRENT_CALLBACK_CONFIGURATION,
244
+ data=pack_payload(
245
+ (
246
+ int(channel),
247
+ int(period),
248
+ bool(value_has_to_change),
249
+ option.value,
250
+ self.__si_to_value(minimum),
251
+ self.__si_to_value(maximum),
252
+ ),
253
+ "B I ! c i i",
254
+ ),
255
+ response_expected=response_expected,
256
+ )
257
+
258
+ async def get_current_callback_configuration(self, channel: int) -> AdvancedCallbackConfiguration:
259
+ """
260
+ Returns the callback configuration as set by :func:`Set Current Callback Configuration`.
261
+ """
262
+ assert channel in (0, 1)
263
+
264
+ _, payload = await self.ipcon.send_request(
265
+ device=self,
266
+ function_id=FunctionID.GET_CURRENT_CALLBACK_CONFIGURATION,
267
+ data=pack_payload((int(channel),), "B"),
268
+ response_expected=True,
269
+ )
270
+ period, value_has_to_change, option, minimum, maximum = unpack_payload(payload, "I ! c i i")
271
+ return AdvancedCallbackConfiguration(
272
+ period, value_has_to_change, Threshold(option), self.__value_to_si(minimum), self.__value_to_si(maximum)
273
+ )
274
+
275
+ async def set_sample_rate(self, rate: _SamplingRate | int, response_expected: bool = True) -> None:
276
+ """
277
+ Sets the sample rate to either 240, 60, 15 or 4 samples per second. The resolution for the rates is 12, 14, 16
278
+ and 18 bit respectively.
279
+
280
+ .. csv-table::
281
+ :header: "Value", "Description"
282
+ :widths: 10, 100
283
+
284
+ "0", "240 samples per second, 12 bit resolution"
285
+ "1", "60 samples per second, 14 bit resolution"
286
+ "2", "15 samples per second, 16 bit resolution"
287
+ "3", "4 samples per second, 18 bit resolution"
288
+ """
289
+ rate = SamplingRate(rate)
290
+
291
+ await self.ipcon.send_request(
292
+ device=self,
293
+ function_id=FunctionID.SET_SAMPLE_RATE,
294
+ data=pack_payload((rate.value,), "B"),
295
+ response_expected=response_expected,
296
+ )
297
+
298
+ async def get_sample_rate(self) -> _SamplingRate:
299
+ """
300
+ Returns the sample rate as set by :func:`Set Sample Rate`.
301
+ """
302
+ _, payload = await self.ipcon.send_request(
303
+ device=self, function_id=FunctionID.GET_SAMPLE_RATE, response_expected=True
304
+ )
305
+
306
+ return SamplingRate(unpack_payload(payload, "B"))
307
+
308
+ async def set_gain(self, gain: _Gain | int, response_expected: bool = True) -> None:
309
+ """
310
+ Sets a gain between 1x and 8x. If you want to measure a very small current, you can increase the gain to get
311
+ some more resolution.
312
+
313
+ Example: If you measure 0.5mA with a gain of 8x the return value will be 4mA.
314
+ """
315
+ gain = Gain(gain)
316
+
317
+ await self.ipcon.send_request(
318
+ device=self,
319
+ function_id=FunctionID.SET_GAIN,
320
+ data=pack_payload((gain.value,), "B"),
321
+ response_expected=response_expected,
322
+ )
323
+
324
+ async def get_gain(self) -> _Gain:
325
+ """
326
+ Returns the gain as set by :func:`Set Gain`.
327
+ """
328
+ _, payload = await self.ipcon.send_request(device=self, function_id=FunctionID.GET_GAIN, response_expected=True)
329
+
330
+ return Gain(unpack_payload(payload, "B"))
331
+
332
+ async def set_channel_led_config(
333
+ self, channel: int, config: LedConfig | int, response_expected: bool = True
334
+ ) -> None:
335
+ """
336
+ Each channel has a corresponding LED. You can turn the LED off, on or show a heartbeat. You can also set the LED
337
+ to "Channel Status". In this mode the LED can either be turned on with a pre-defined threshold or the intensity
338
+ of the LED can change with the measured value.
339
+
340
+ You can configure the channel status behavior with :func:`Set Channel LED Status Config`.
341
+
342
+ By default, all channel LEDs are configured as "Channel Status".
343
+ """
344
+ assert channel in (0, 1)
345
+ config = LedConfig(config)
346
+
347
+ await self.ipcon.send_request(
348
+ device=self,
349
+ function_id=FunctionID.SET_CHANNEL_LED_CONFIG,
350
+ data=pack_payload((int(channel), config.value), "B B"),
351
+ response_expected=response_expected,
352
+ )
353
+
354
+ async def get_channel_led_config(self, channel: int) -> LedConfig:
355
+ """
356
+ Returns the channel LED configuration as set by :func:`Set Channel LED Config`.
357
+ """
358
+ assert channel in (0, 1)
359
+
360
+ _, payload = await self.ipcon.send_request(
361
+ device=self,
362
+ function_id=FunctionID.GET_CHANNEL_LED_CONFIG,
363
+ data=pack_payload((int(channel),), "B"),
364
+ response_expected=True,
365
+ )
366
+
367
+ return LedConfig(unpack_payload(payload, "B"))
368
+
369
+ async def set_channel_led_status_config( # pylint: disable=too-many-arguments,too-many-positional-arguments
370
+ self,
371
+ channel: int,
372
+ minimum: float | Decimal,
373
+ maximum: float | Decimal,
374
+ config: _ChannelLedStatusConfig | int,
375
+ response_expected: bool = True,
376
+ ) -> None:
377
+ """
378
+ Sets the channel LED status config. This config is used if the channel LED is configured as "Channel Status",
379
+ see :func:`Set Channel LED Config`. The `minimum` and `maximum` values are given in A.
380
+
381
+ For each channel you can choose between threshold and intensity mode.
382
+
383
+ In threshold mode you can define a positive or a negative threshold. For a positive threshold set the "min"
384
+ parameter to the threshold value in A above which the LED should turn on and set the "max" parameter to 0.
385
+ Example: If you set a positive threshold of 10mA, the LED will turn on as soon as the current exceeds 10mA and
386
+ turn off again if it goes below 10mA. For a negative threshold set the "max" parameter to the threshold value in
387
+ A below which the LED should turn on and set the "min" parameter to 0. Example: If you set a negative threshold
388
+ of 10mA, the LED will turn on as soon as the current goes below 10mA and the LED will turn off when the current
389
+ exceeds 10mA.
390
+
391
+ In intensity mode you can define a range in A that is used to scale the brightness of the LED. Example with
392
+ min=4mA and max=20mA: The LED is off at 4mA and below, on at 20mA and above and the brightness is linearly
393
+ scaled between the values 4mA and 20mA. If the min value is greater than the max value, the LED brightness is
394
+ scaled the other way around.
395
+ """
396
+ assert channel in (0, 1)
397
+ config = ChannelLedStatusConfig(config)
398
+
399
+ await self.ipcon.send_request(
400
+ device=self,
401
+ function_id=FunctionID.SET_CHANNEL_LED_STATUS_CONFIG,
402
+ data=pack_payload(
403
+ (
404
+ int(channel),
405
+ self.__si_to_value(minimum),
406
+ self.__si_to_value(maximum),
407
+ config.value,
408
+ ),
409
+ "B i i B",
410
+ ),
411
+ response_expected=response_expected,
412
+ )
413
+
414
+ async def get_channel_led_status_config(self, channel: int) -> GetChannelLEDStatusConfig:
415
+ """
416
+ Returns the channel LED status configuration as set by :func:`Set Channel LED Status Config`.
417
+ """
418
+ assert channel in (0, 1)
419
+
420
+ _, payload = await self.ipcon.send_request(
421
+ device=self,
422
+ function_id=FunctionID.GET_CHANNEL_LED_STATUS_CONFIG,
423
+ data=pack_payload((int(channel),), "B"),
424
+ response_expected=True,
425
+ )
426
+
427
+ minimum, maximum, config = unpack_payload(payload, "i i B")
428
+ return GetChannelLEDStatusConfig(
429
+ self.__value_to_si(minimum), self.__value_to_si(maximum), ChannelLedStatusConfig(config)
430
+ )
431
+
432
+ @staticmethod
433
+ def __value_to_si(value: int) -> Decimal:
434
+ """
435
+ Convert the sensor value (nA) to SI units (A)
436
+ """
437
+ return Decimal(value) / 1_000_000_000
438
+
439
+ @staticmethod
440
+ def __si_to_value(value: float | Decimal) -> int:
441
+ """
442
+ Convert SI units (A) to the sensor value (nA). Rounding avoids floating point errors, e.g. 0.0029 A * 1e9
443
+ would otherwise result in 2899999 nA.
444
+ """
445
+ return round(Decimal(value) * 1_000_000_000)
446
+
447
+ async def read_events(
448
+ self,
449
+ events: tuple[int | _CallbackID, ...] | list[int | _CallbackID] | None = None,
450
+ sids: tuple[int, ...] | list[int] | None = None,
451
+ ) -> AsyncGenerator[Event, None]:
452
+ registered_events = set()
453
+ if events:
454
+ for event in events:
455
+ registered_events.add(self.CallbackID(event))
456
+ if sids is not None:
457
+ for sid in sids:
458
+ for callback in self.SID_TO_CALLBACK.get(sid, []):
459
+ registered_events.add(callback)
460
+
461
+ if not events and sids is None:
462
+ registered_events = set(self.CALLBACK_FORMATS.keys())
463
+
464
+ async for header, payload in super()._read_events():
465
+ try:
466
+ function_id = CallbackID(header.function_id)
467
+ except ValueError:
468
+ # Invalid header. Drop the packet.
469
+ continue
470
+ if function_id in registered_events:
471
+ channel, value = unpack_payload(payload, self.CALLBACK_FORMATS[function_id])
472
+ if sids is not None and channel not in sids:
473
+ # We got a reply from the wrong channel, maybe there is another callback running on that other
474
+ # channel, so we ignore the value
475
+ continue
476
+ yield Event(self, channel, function_id, self.__value_to_si(value))
@@ -325,7 +325,7 @@ class BrickletIndustrialDualAnalogInV2(BrickletWithMCU):
325
325
  .. versionadded:: 2.0.6$nbsp;(Plugin)
326
326
  """
327
327
  _, payload = await self.ipcon.send_request(
328
- device=self, function_id=FunctionID.GET_VOLTAGE_CALLBACK_CONFIGURATION, response_expected=True
328
+ device=self, function_id=FunctionID.GET_ALL_VOLTAGES_CALLBACK_CONFIGURATION, response_expected=True
329
329
  )
330
330
  return SimpleCallbackConfiguration(*unpack_payload(payload, "I !"))
331
331
 
@@ -540,4 +540,4 @@ class BrickletIndustrialDualAnalogInV2(BrickletWithMCU):
540
540
 
541
541
  elif function_id is CallbackID.ALL_VOLTAGES:
542
542
  values = unpack_payload(payload, self.CALLBACK_FORMATS[function_id])
543
- yield Event(self, 2, function_id, (self.__value_to_si(value) for value in values))
543
+ yield Event(self, 2, function_id, tuple(self.__value_to_si(value) for value in values))
@@ -379,14 +379,14 @@ class BrickletThermocoupleV2(BrickletWithMCU):
379
379
  if self.__sensor_type is SensorType.TYPE_G8:
380
380
  return Decimal(value / 8 / 1.6 / 2**17)
381
381
  if self.__sensor_type is SensorType.TYPE_G32:
382
- return Decimal(value / 8 / 1.6 / 2**17)
382
+ return Decimal(value / 32 / 1.6 / 2**17)
383
383
  return Decimal(value + 27315) / 100
384
384
 
385
385
  def __si_to_value(self, value: float | Decimal) -> int:
386
386
  if self.__sensor_type is SensorType.TYPE_G8:
387
387
  return int(float(value) * 8 * 1.6 * 2**17)
388
388
  if self.__sensor_type is SensorType.TYPE_G32:
389
- return int(float(value) * 8 * 1.6 * 2**17)
389
+ return int(float(value) * 32 * 1.6 * 2**17)
390
390
  return int(value * 100) - 27315
391
391
 
392
392
  async def read_events(
@@ -15,6 +15,7 @@ from .bricklet_barometer import BrickletBarometer
15
15
  from .bricklet_barometer_v2 import BrickletBarometerV2
16
16
  from .bricklet_humidity import BrickletHumidity
17
17
  from .bricklet_humidity_v2 import BrickletHumidityV2
18
+ from .bricklet_industrial_dual_0_20ma_v2 import BrickletIndustrialDual020mAV2
18
19
  from .bricklet_industrial_dual_analog_in_v2 import BrickletIndustrialDualAnalogInV2
19
20
  from .bricklet_industrial_ptc import BrickletIndustrialPtc
20
21
  from .bricklet_io4_v2 import BrickletIO4V2
@@ -71,6 +72,7 @@ device_factory.register(BrickletBarometer)
71
72
  device_factory.register(BrickletBarometerV2)
72
73
  device_factory.register(BrickletHumidity)
73
74
  device_factory.register(BrickletHumidityV2)
75
+ device_factory.register(BrickletIndustrialDual020mAV2)
74
76
  device_factory.register(BrickletIndustrialDualAnalogInV2)
75
77
  device_factory.register(BrickletIndustrialPtc)
76
78
  device_factory.register(BrickletIO4V2)
@@ -61,6 +61,7 @@ class DeviceIdentifier(Enum):
61
61
  BRICKLET_IO_4_V2 = 2111
62
62
  BRICKLET_TEMPERATURE_V2 = 2113
63
63
  BRICKLET_BAROMETER_V2 = 2117
64
+ BRICKLET_INDUSTRIAL_DUAL_0_20MA_V2 = 2120
64
65
  BRICKLET_INDUSTRIAL_DUAL_ANALOG_IN_V2 = 2121
65
66
  BRICKLET_ISOLATOR = 2122
66
67
  BRICKLET_AMBIENT_LIGHT_V3 = 2131
@@ -110,6 +111,11 @@ class BrickletPort(Enum):
110
111
  B = "b"
111
112
  C = "c"
112
113
  D = "d"
114
+ E = "e" # Only available on Bricks/HATs with more than four ports
115
+ F = "f"
116
+ G = "g"
117
+ H = "h"
118
+ Z = "z" # Bricklets connected to an Isolator Bricklet are always at position 'z'
113
119
 
114
120
 
115
121
  class GetSPITFPErrorCount(NamedTuple):
@@ -183,7 +189,7 @@ class Device:
183
189
  the position, the hardware and firmware version as well as the
184
190
  device identifier.
185
191
 
186
- The position can be 'a', 'b', 'c' or 'd'.
192
+ The position can be 'a' to 'h' or 'z' (behind an Isolator Bricklet).
187
193
 
188
194
  The device identifier numbers can be found :ref:`here <device_identifier>`.
189
195
  |device_identifier_constant|
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinkerforge-async
3
- Version: 1.6.2
3
+ Version: 1.8.0
4
4
  Summary: Python3 AsyncIO Tinkerforge driver
5
5
  Author-email: Patrick Baus <patrick.baus@physik.tu-darmstadt.de>
6
6
  License-Expression: GPL-3.0-or-later
@@ -9,11 +9,11 @@ Project-URL: Bug Tracker, https://github.com/PatrickBaus/tinkerforge_async/issue
9
9
  Project-URL: Download, https://github.com/PatrickBaus/tinkerforge_async/releases
10
10
  Keywords: IoT,Tinkerforge,API
11
11
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
12
  Classifier: Programming Language :: Python :: 3.11
15
13
  Classifier: Programming Language :: Python :: 3.12
16
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
17
  Classifier: Development Status :: 5 - Production/Stable
18
18
  Classifier: Operating System :: OS Independent
19
19
  Classifier: Intended Audience :: Developers
@@ -21,10 +21,9 @@ Classifier: Intended Audience :: Science/Research
21
21
  Classifier: Natural Language :: English
22
22
  Classifier: Topic :: Home Automation
23
23
  Classifier: Topic :: Scientific/Engineering
24
- Requires-Python: >=3.9
24
+ Requires-Python: >=3.11
25
25
  Description-Content-Type: text/markdown
26
26
  License-File: LICENSE
27
- Requires-Dist: typing-extensions; python_version < "3.11"
28
27
  Provides-Extra: dev
29
28
  Requires-Dist: black; extra == "dev"
30
29
  Requires-Dist: build; extra == "dev"
@@ -71,6 +70,7 @@ The library is fully type-hinted.
71
70
  | [Barometer 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Barometer_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
72
71
  | [Humidity](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity.html) |:heavy_check_mark:|:heavy_check_mark:|
73
72
  | [Humidity 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
73
+ | [Industrial Dual 0-20mA 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_020mA_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
74
74
  | [Industrial Dual Analog In 2.0](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_Analog_In_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
75
75
  | [Industrial PTC](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_PTC.html) |:heavy_check_mark:|:heavy_check_mark:|
76
76
  | [IO-4 2.0](https://www.tinkerforge.com/de/doc/Hardware/Bricklets/IO4_V2.html) |:heavy_check_mark:|:heavy_check_mark:|
@@ -13,6 +13,7 @@ tinkerforge_async/bricklet_barometer.py
13
13
  tinkerforge_async/bricklet_barometer_v2.py
14
14
  tinkerforge_async/bricklet_humidity.py
15
15
  tinkerforge_async/bricklet_humidity_v2.py
16
+ tinkerforge_async/bricklet_industrial_dual_0_20ma_v2.py
16
17
  tinkerforge_async/bricklet_industrial_dual_analog_in_v2.py
17
18
  tinkerforge_async/bricklet_industrial_ptc.py
18
19
  tinkerforge_async/bricklet_io16.py
@@ -1,7 +1,4 @@
1
1
 
2
- [:python_version < "3.11"]
3
- typing-extensions
4
-
5
2
  [dev]
6
3
  black
7
4
  build