tinkerforge-async
A Python asyncio Tinkerforge API implementation
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 2 committers (50.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.6%) to scientific vocabulary
Keywords
Repository
A Python asyncio Tinkerforge API implementation
Basic Info
Statistics
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
- Releases: 13
Topics
Metadata Files
README.md
TinkerforgeAsync
This is a reimplementation of the Tinkerforge Python bindings (original Python bindings) using Python 3 asyncio. The original bindings used threads to manage the blocking operations. A much cleaner implementation is possible using the await syntax from asyncio.
Note: This API implementation is not an official Tinkerforge implementation. I am in no way affiliated with the Tinkerforge GmbH. Use at your own risk. If you find any bugs, please report them.
The library is fully type-hinted.
Supported Bricks/Bricklets
|Brick|Supported|Tested|Comments| |--|--|--|--| |Master|:heavycheckmark:|:heavycheckmark:| |
| Bricklet |Supported|Tested| |--------------------------------------------------------------------------------------------------------------------------|--|--| | Ambient Light 2.0 |:heavycheckmark:|:heavycheckmark:| | Ambient Light 3.0 |:heavycheckmark:|:heavycheckmark:| | Analog In |:heavycheckmark:|:heavycheckmark:| | Barometer |:heavycheckmark:|:heavycheckmark:| | Barometer 2.0 |:heavycheckmark:|:heavycheckmark:| | Humidity |:heavycheckmark:|:heavycheckmark:| | Humidity 2.0 |:heavycheckmark:|:heavycheckmark:| | Industrial Dual Analog In 2.0 |:heavycheckmark:|:heavycheckmark:| | Industrial PTC |:heavycheckmark:|:heavycheckmark:| | IO-4 2.0 |:heavycheckmark:|:heavycheckmark:| | IO-16 |:heavycheckmark:|:heavycheckmark:| | Isolator |:heavycheckmark:|:heavycheckmark:| | Moisture |:heavycheckmark:|:heavycheckmark:| | Motion Detector 2.0 |:heavycheckmark:|:heavycheckmark:| | PTC |:heavycheckmark:|:heavycheckmark:| | PTC 2.0 |:heavycheckmark:|:heavycheckmark:| | RS232 2.0 |:heavycheckmark:|:heavycheckmark:| | Segment Display 4x7 |:heavycheckmark:|:heavycheckmark:| | Segment Display 4x7 2.0 |:heavycheckmark:|:heavycheckmark:| | Temperature |:heavycheckmark:|:heavycheckmark:| | Temperature 2.0 |:heavycheckmark:|:heavycheckmark:| | Thermocouple 2.0 |:heavycheckmark:|:heavycheckmark:|
Documentation
The documentation is currently work in progress. The full documentation will be moved to https://patrickbaus.github.io/tinkerforge_async/. Below you can find the current state of the documentation. I use the Numpydoc style for documentation and Sphinx for compiling it.
Setup
To install the library in a virtual environment (always use venvs with every project):
bash
python3 -m venv env # virtual environment, optional
source env/bin/activate # only if the virtual environment is used
pip install tinkerforge-async
Changes made to the API
Some design choices of the original Tinkerforge API are overly complex. I therefore replaced them with a simpler and more intuitive approach. A list of things that were changed can be found below:
Design Changes
- Only Python 3 is supported (3.9+)
- Replaced threads with an async event loop
- Completely rewritten how responses from bricks/bricklets work. All setters now have a
response_expectedparameter, which is set toTrueby default. If there is an error when calling the function, it will then raise an exception - either anAttributeErrorif the function is unknown, or aValueErrorif one or more parameters are invalid.
Old style:
python
bricklet = BrickletHumidity(UID, ipcon)
bricklet.set_response_expected(
BrickletHumidity.FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD, True
)
bricklet.set_humidity_callback_period(1000)
New style:
python
bricklet = BrickletHumidity(UID, ipcon)
await bricklet.set_humidity_callback_period(
1000, response_expected=True
) # Raises an exception if unsuccessful
- Replaced all constants with Enums and enforced their use using assertions. This will allow beginners to spot their mistakes earlier and make the code more readable, including any debug output statements.
Old style:
python
class BrickletHumidity(Device):
FUNCTION_GET_HUMIDITY = 1
FUNCTION_GET_ANALOG_VALUE = 2
FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD = 3
FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD = 4
FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 5
FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 6
FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD = 7
FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD = 8
FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 9
FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 10
FUNCTION_SET_DEBOUNCE_PERIOD = 11
FUNCTION_GET_DEBOUNCE_PERIOD = 12
FUNCTION_GET_IDENTITY = 255
New style:
python
class BrickletHumidity(Device):
@unique
class FunctionID(Enum):
GET_HUMIDITY = 1
GET_ANALOG_VALUE = 2
SET_HUMIDITY_CALLBACK_PERIOD = 3
GET_HUMIDITY_CALLBACK_PERIOD = 4
SET_ANALOG_VALUE_CALLBACK_PERIOD = 5
GET_ANALOG_VALUE_CALLBACK_PERIOD = 6
SET_HUMIDITY_CALLBACK_THRESHOLD = 7
GET_HUMIDITY_CALLBACK_THRESHOLD = 8
SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 9
GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 10
SET_DEBOUNCE_PERIOD = 11
GET_DEBOUNCE_PERIOD = 12
- Moved from base58 encoded uids to integers.
- Moved from callbacks to queues in order to keep users out of the callback hell. It makes the code style more readable when using the await syntax anyway.
- Payloads will now be decoded by the Device object and no longer by the ip_connection. This makes the code a lot more readable. To do so, the payload and decoded header will be handed to the device. It will then decode it, if possible, and pass it on to the queue.
- If physical quantities are measured we will now return standard SI units, not some unexpected stuff like centi °C (Temperature Bricklet). To preserve the precision the Decimal package is used. The only exception to this rule is the use of °C for temperature. This is for convenience.
- All callbacks now contain a timestamp (Unix timestamp) and the device object.
Example:
Event(timestamp=1658756708.6839857, sender=Temperature Bricklet 2.0 with uid 161085 connected at IPConnectionAsync(192.168.1.164:4223), sid=0, function_id=CallbackID.TEMPERATURE, payload=305.46)
- Added the concept of secondary ids (
sid). By default, the secondary id is0. If there is more than one sensor on the bricklet, they will have asidvalue of 1,2, etc. This is especially useful for sensors like the Industrial Dual Analog In Bricklet 2.0, which returns its two channels via the same callback. - New functions:
BrickMaster.set_wpa_enterprise_username(username): Set the WPA enterprise username without calling BrickMaster.set_wifi_certificate(). Takes a string instead of an array of int.
BrickMaster.set_wpa_enterprise_password(password): Set the WPA enterprise password without calling BrickMaster.set_wifi_certificate(). Takes a string instead of an array of int.
BrickMaster.get_wpa_enterprise_username(): Get the WPA enterprise password without calling BrickMaster.get_wifi_certificate(). Also returns a string instead of an array of int.
BrickMaster.get_wpa_enterprise_password(): Get the WPA enterprise password without calling BrickMaster.get_wifi_certificate(). Also returns a string instead of an array of int.
IP Connection
IPConnection.authenticate(secret): removed. This can now be done through connect()IPConnection.set_timeout/IPConnection.get_timeout: Replaced by a propertyIPConnection.register_callback(callback_id, function): Replaced byregister_event_queue()IPConnection.connect(host, port=4223, authentication_secret=''): Ifauthentication_secretis not empty, try to authenticate.
IO-4 Bricklet 2.0
BrickletIO4V2.set_pwm_configuration()will now take the frequency in units of Hz and the duty cycle is normalized to 1, so it will take a float from [0...1].BrickletIO4V2.get_pwm_configuration()will return the frequency in units of Hz and the duty cycle is normalized to 1.BrickletIO4V2.set_edge_count_callback_configuration()sets the callback configuration for the edge counter callback. Its secondary ids are in [5...8] for channels [0...3].BrickletIO4V2.get_edge_count_callback_configuration()returns the callback configuration for the edge counter callback.
Master Brick
BrickMaster.set_wifi_configuration()/BrickMaster.get_wifi_configuration()will take/return all ips in natural orderBrickMaster.set_ethernet_configuration()/BrickMaster.get_ethernet_configuration()will take/return all ips in natural orderBrickMaster.write_wifi2_serial_port()will only accept abytestringand no length argument. The length will be automatically determined from the string.BrickMaster.set_wifi2_status_led(enabled)added. This allows setting the status led by value instead of callingenable_wifi2_status_led/disable_wifi2_status_led
PTC Bricklet
BrickletPtc()takes an additional parameter to define the type of sensor. The options areBrickletPtc.SensorType.PT_100andBrickletPtc.SensorType.PT_1000. This only determines the resistance returned by the bricklet. The default isBrickletPtc.SensorType.PT_100.BrickletPtc.sensor_typegetter and setter to change the type of sensor used.
PTC Bricklet 2.0
BrickletPtcV2()takes an additional parameter to define the type of sensor. The options areBrickletPtc.SensorType.PT_100andBrickletPtc.SensorType.PT_1000. This only determines the resistance returned by the bricklet. The default isBrickletPtc.SensorType.PT_100.BrickletPtcV2.sensor_typegetter and setter to change the type of sensor used.
Thermocouple Bricklet 2.0
BrickletThermocoupleV2()takes an additional parameter to define the type of sensor. The options are of typeBrickletThermocoupleV2.SensorType. The default isBrickletPtc.SensorType.TYPE_K.BrickletThermocoupleV2.sensor_typegetter and setter to change the type of sensor used.
Segment Display 4x7 Bricklet 2.0
BrickletSegmentDisplay4x7V2.set_segments()takes alist/tupleof 4intinstead of digit0, digit1, digit2, digit3. This is the same API as the older Segment Display 4x7 Bricklet.
Setup
There are currently no packages available at the PyPi repository. To install the module, clone the repository and run:
bash
python3 -m venv env # virtual environment, optional
source env/bin/activate # only if the virtual environment is used
python3 setup.py install
Versioning
I use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Patrick Baus - Initial work - PatrickBaus
License
This project is licensed under the GPL v3 license - see the LICENSE file for details
Owner
- Name: Patrick Baus
- Login: PatrickBaus
- Kind: user
- Location: Darmstadt, Germany
- Company: TU Darmstadt
- Repositories: 10
- Profile: https://github.com/PatrickBaus
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: Baus
given-names: Patrick
orcid: https://orcid.org/0000-0002-0318-5245
title: "TinkerforgeAsync"
version: 1.2.0
date-released: 2021-07-16
GitHub Events
Total
- Release event: 3
- Delete event: 10
- Push event: 18
- Pull request event: 22
- Create event: 13
Last Year
- Release event: 3
- Delete event: 10
- Push event: 18
- Pull request event: 22
- Create event: 13
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 291
- Total Committers: 2
- Avg Commits per committer: 145.5
- Development Distribution Score (DDS): 0.003
Top Committers
| Name | Commits | |
|---|---|---|
| Patrick Baus | p****s@p****e | 290 |
| Patrick Baus | g****b@m****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 5 months ago
All Time
- Total issues: 1
- Total pull requests: 15
- Average time to close issues: over 1 year
- Average time to close pull requests: about 1 hour
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 15
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 0
- Pull requests: 12
- Average time to close issues: N/A
- Average time to close pull requests: 2 minutes
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- PatrickBaus (1)
Pull Request Authors
- PatrickBaus (23)
- dependabot[bot] (4)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 160 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 10
- Total maintainers: 1
pypi.org: tinkerforge-async
Python3 AsyncIO Tinkerforge driver
- Homepage: https://github.com/PatrickBaus/tinkerforge_async
- Documentation: https://tinkerforge-async.readthedocs.io/
- License: gpl-3.0
-
Latest release: 1.6.2
published 6 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/setup-python v4 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- typing-extensions python_version <'3.11'
- actions/checkout v4 composite
- actions/setup-python v5 composite
- pre-commit/action v3.0.1 composite