rhyst / linak-controller

A Python script to control Linak standing desks.
MIT License
358 stars 50 forks source link

Misc improvement #63

Closed smailzhu closed 1 year ago

smailzhu commented 1 year ago

Thanks for writing this handy tools! Feel free to pick revise if it's help

Catch OSError exception

While execute idasen-controller on Windows without Bluetooth enable will get error message from OSError

(ikeaDesk) C:\>idasen-controller
Connecting
Something unexpected went wrong:
Traceback (most recent call last):
  File "c:\...\ikeadesk\lib\site-packages\idasen_controller\main.py", line 483, in main
    client = await connect()
  File "c:\...\ikeadesk\lib\site-packages\idasen_controller\main.py", line 323, in connect
    await client.connect(timeout=config["connection_timeout"])
  File "c:\...\ikeadesk\lib\site-packages\bleak\__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "c:\...\ikeadesk\lib\site-packages\bleak\backends\winrt\client.py", line 239, in connect
    device = await BleakScanner.find_device_by_address(
  File "c:\...\ikeadesk\lib\site-packages\bleak\__init__.py", line 286, in find_device_by_address
    return await cls.find_device_by_filter(
  File "c:\...\ikeadesk\lib\site-packages\bleak\__init__.py", line 323, in find_device_by_filter
    async with cls(detection_callback=apply_filter, **kwargs):
  File "c:\...\ikeadesk\lib\site-packages\bleak\__init__.py", line 126, in __aenter__
    await self._backend.start()
  File "c:\...\ikeadesk\lib\site-packages\bleak\backends\winrt\scanner.py", line 256, in start
    self.watcher.start()
OSError: [WinError -2147020577] The device is not ready for use

With this revision will get

(ikeaDesk) C:\>idasen-controller
[WinError -2147020577] The device is not ready for use

Check speed before log in move_to

Which can prevent speed 0 log printed

Shows favourite target height while prompt

Prompt as Moving to favourite height: stand (1100 mm) but not Moving to favourite height: stand

Early return while nothing to do

Check target height and initial height before call move_to