@ericguan04 made a nice PR adding yolink devices:
main ← ericguan04:yo_link_api
opened 09:08PM - 20 Aug 25 UTC
Added YoLink API wrapper to PLR to integrate the YoLink family of devices. More … information can be found in the forum post: https://discuss.pylabrobot.org/t/yolink-api-integration-advice/297
In the main pylabrobot directory, I added the yolink directory and tried my best to follow the conventions already set.
There are two ways to use the YoLink API wrapper:
- Method 1 allows the user to directly use the YoLink access token to setup the YoLink backend
```
from pylabrobot.yolink import YoLink, Sensor, Outlet
api_key = "..."
backend = YoLink(api_key=api_key)
s = Sensor(backend=backend, sensor_name="Coldspot Fridge Sensor")
await s.setup()
temp = await s.get_temperature()
humidity = await s.get_humidity()
await s.stop()
```
- Method 2 allows the user to use their YoLink api credentials (UAID and secret key) to setup the YoLink backend
```
from pylabrobot.yolink import YoLink, Sensor, Outlet
client_id = "..."
client_secret = "..."
backend = YoLink(client_id=client_id, client_secret=client_secret)
s = Sensor(backend=backend, sensor_name="Coldspot Fridge Sensor")
await s.setup()
temp = await s.get_temperature()
humidity = await s.get_humidity()
await s.stop()
```
More details about getting UAID, Secret Key, and Access Token can be found here: http://doc.yosmart.com/docs/overall/qsg_uac
- I personally found it a bit confusing the first time going through it so I can probably write some documentation on how to set this up.
Currently, the two types of devices I implemented are the `Sensor()` and the `Outlet()`. The sensor can return readings such as temperature, humidity, etc, while the outlet (yolink smart power strip) includes both read and write commands. The forum post has more details about this.
YoLink also comes with a few additional dependencies that aren't already in pylabrobot:
```
dependencies = [
"aiohttp>=3.8.1",
"aiomqtt>=2.0.0,<3.0.0",
"pydantic>=2.0.0",
"tenacity>=8.1.0",
]
```
How should these be handled?
I am setting this as a draft PR since I have only done preliminary testing with the API wrapper. Theoretically, the rest of the PLR code should function as normal since the YoLink code doesn't interact with the rest of the codebase, but testing needs to be done to be sure. Additionally, I tried to follow PLR conventions + best practices but feedback on the code structure and implementation from someone more experienced would be great.
one of the devices he included is a controlled outlet. While the code is very nice and readable and uses PLR’s (new) YoLink class, since this is very general (not necessarily a lab automation machine), I am not sure it should go in PLR. I am undecided on this.
Curious to hear what other members in the community think.
1 Like