Skip to content

Commit de81cd1

Browse files
authored
Fix disconnect issues (#28)
1 parent 212c439 commit de81cd1

File tree

5 files changed

+639
-180
lines changed

5 files changed

+639
-180
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ jobs:
2828
uses: wearerequired/lint-action@v2
2929
with:
3030
black: true
31+
black_auto_fix: false
3132
flake8: true
33+
flake8_auto_fix: false
3234

33-
- uses: actions/checkout@v3
3435
- uses: isort/isort-action@v1.0.0
3536

3637
run-tests:

examples/read.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
import asyncio
22
import sys
33

4-
from bleak.backends.device import BLEDevice
4+
from bleak import BleakScanner
55

66
from pyfreshintellivent import FreshIntelliVent
77

88

99
async def main():
10-
sky = FreshIntelliVent()
10+
client = FreshIntelliVent()
1111
address = sys.argv[1]
12-
authentication_code = sys.argv[2]
12+
authentication_code = None
13+
if len(sys.argv) == 3:
14+
sys.argv[2]
1315

14-
ble_device = BLEDevice(address=address)
16+
ble_device = await BleakScanner.find_device_by_address(address)
17+
18+
if ble_device is None:
19+
print("Couldn't find any devices")
20+
return
1521

1622
try:
17-
async with sky.connect(ble_device) as client:
23+
print("Connecting...")
24+
await client.connect(ble_device)
25+
print("Connected")
26+
27+
await client.fetch_device_information()
28+
29+
if authentication_code is None:
30+
print("No authentication code, skipping authentication")
31+
else:
1832
await client.authenticate(authentication_code=authentication_code)
33+
print("Authenticated")
1934

20-
sensors = await client.fetch_sensor_data()
21-
print(f"Status: {sensors.as_dict()}")
35+
sensors = await client.fetch_sensor_data()
36+
print(f"Status: {sensors.as_dict()}")
2237

23-
boost = await client.fetch_boost()
24-
print(f"Boost: {boost}")
38+
boost = await client.fetch_boost()
39+
print(f"Boost: {boost}")
2540

26-
constant_speed = await client.fetch_constant_speed()
27-
print(f"Constant speed: {constant_speed}")
41+
constant_speed = await client.fetch_constant_speed()
42+
print(f"Constant speed: {constant_speed}")
2843

29-
humidity = await client.fetch_humidity()
30-
print(f"Humidity: {humidity}")
44+
humidity = await client.fetch_humidity()
45+
print(f"Humidity: {humidity}")
3146

32-
light_and_voc = await client.fetch_light_and_voc()
33-
print(f"Light and VOC: {light_and_voc}")
47+
light_and_voc = await client.fetch_light_and_voc()
48+
print(f"Light and VOC: {light_and_voc}")
3449

35-
pause = await client.fetch_pause()
36-
print(f"Pause: {pause}")
50+
pause = await client.fetch_pause()
51+
print(f"Pause: {pause}")
3752

38-
timer = await client.fetch_timer()
39-
print(f"Timer: {timer}")
53+
timer = await client.fetch_timer()
54+
print(f"Timer: {timer}")
4055
except Exception as e:
56+
await client.disconnect()
4157
print(e)
4258

4359

44-
asyncio.run(main())
60+
if __name__ == "__main__":
61+
asyncio.run(main())

0 commit comments

Comments
 (0)