Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wakeup for the Linak DPG1C controller #370

Merged
merged 7 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added a `wakeup` method for compatibility with the Linak DPG1C controller.

## [0.10.3] - 2023-10-08
### Added
- Added support for python 3.12.
Expand Down
24 changes: 24 additions & 0 deletions idasen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
_UUID_COMMAND: str = "99fa0002-338a-1024-8a49-009c0215f78a"
_UUID_REFERENCE_INPUT: str = "99fa0031-338a-1024-8a49-009c0215f78a"
_UUID_ADV_SVC: str = "99fa0001-338a-1024-8a49-009c0215f78a"
_UUID_DPG: str = "99fa0011-338a-1024-8a49-009c0215f78a"

_COMMAND_REFERENCE_INPUT_STOP: bytearray = bytearray([0x01, 0x80])
_COMMAND_UP: bytearray = bytearray([0x47, 0x00])
_COMMAND_DOWN: bytearray = bytearray([0x46, 0x00])
_COMMAND_STOP: bytearray = bytearray([0xFF, 0x00])
_COMMAND_WAKEUP: bytearray = bytearray([0xFE, 0x00])


# height calculation offset in meters, assumed to be the same for all desks
Expand Down Expand Up @@ -144,6 +146,7 @@ async def connect(self):
while True:
try:
await self._client.connect()
await self.wakeup()
return
except Exception:
if i >= self.RETRY_COUNT:
Expand Down Expand Up @@ -238,6 +241,27 @@ def mac(self) -> str:
"""
return self._mac

async def wakeup(self):
"""
Wakeup the controller from sleep.

This exists for compatibility with the Linak DPG1C controller,
it is not necessary with the original idasen controller.

>>> async def example() -> str:
... async with IdasenDesk(mac="AA:AA:AA:AA:AA:AA") as desk:
... await desk.wakeup()
>>> asyncio.run(example())
"""
# https://github.com/rhyst/linak-controller/issues/32#issuecomment-1784055470
await self._client.write_gatt_char(_UUID_DPG, b"\x7F\x86\x00")
await self._client.write_gatt_char(
_UUID_DPG,
b"\x7F\x86\x80\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D"
b"\x0E\x0F\x10\x11",
)
await self._client.write_gatt_char(_UUID_COMMAND, _COMMAND_WAKEUP)

async def move_up(self):
"""
Move the desk upwards.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_idasen.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def test_move_abort_when_no_movement():
async def write_gatt_char_mock(
uuid: str, command: bytearray, response: bool = False
):
if client.write_gatt_char.call_count == 1:
if client.write_gatt_char.call_count == 4:
assert desk.is_moving
client._height -= 0.001

Expand All @@ -171,7 +171,7 @@ async def test_move_stop():
async def write_gatt_char_mock(
uuid: str, command: bytearray, response: bool = False
):
if client.write_gatt_char.call_count == 1:
if client.write_gatt_char.call_count == 4:
assert desk.is_moving
# Force this method to behave asynchronously, otherwise it will block the
# eventloop
Expand Down