Skip to content

Commit

Permalink
Merge pull request #76 from zweckj/fix/bt
Browse files Browse the repository at this point in the history
bugfix: BT improvements
  • Loading branch information
zweckj authored Dec 30, 2024
2 parents efd2f34 + 07f6f13 commit ad6a4fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pylamarzocco/clients/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import asyncio
import base64
import json
import logging
Expand Down Expand Up @@ -134,18 +135,24 @@ async def authenticate() -> None:
await client.write_gatt_char(
char_specifier=AUTH_CHARACTERISTIC,
data=auth_string,
response=False,
)
except (BleakError, TimeoutError) as e:
raise BluetoothConnectionFailed(
f"Failed to connect to machine with Bluetooth: {e}"
) from e

await authenticate()
await asyncio.sleep(0.1)
_logger.debug(
"Sending bluetooth message: %s to %s", message, characteristic
)

await client.write_gatt_char(char_specifier=characteristic, data=message)
await client.write_gatt_char(
char_specifier=characteristic,
data=message,
response=False,
)

async def _write_bluetooth_json_message(
self,
Expand Down
2 changes: 1 addition & 1 deletion pylamarzocco/clients/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def websocket_connect(
) as ws:
self.websocket = ws
if self.websocket_disconnected:
_LOGGER.debug("Websocket reconnected")
_LOGGER.warning("Websocket reconnected")
self.websocket_disconnected = False
async for msg in ws:
if msg.type in (WSMsgType.CLOSING, WSMsgType.CLOSED):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pylamarzocco"
version = "1.4.4"
version = "1.4.5"
license = { text = "MIT" }
description = "A Python implementation of the new La Marzocco API"
readme = "README.md"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ async def test_bluetooth_set_power(
mock_bleak.write_gatt_char.assert_any_call( # type: ignore[attr-defined]
char_specifier=AUTH_CHARACTERISTIC,
data=b"dXNlcm5hbWU6c2VyaWFs@dG9rZW4=",
response=False,
)

mock_bleak.write_gatt_char.assert_called_with( # type: ignore[attr-defined]
char_specifier=SETTINGS_CHARACTERISTIC,
data=b'{"name":"MachineChangeMode","parameter":{"mode":"BrewingMode"}}\x00',
response=False,
)


Expand All @@ -39,11 +41,13 @@ async def test_bluetooth_set_steam(
mock_bleak.write_gatt_char.assert_any_call( # type: ignore[attr-defined]
char_specifier=AUTH_CHARACTERISTIC,
data=b"dXNlcm5hbWU6c2VyaWFs@dG9rZW4=",
response=False,
)

mock_bleak.write_gatt_char.assert_called_with( # type: ignore[attr-defined]
char_specifier=SETTINGS_CHARACTERISTIC,
data=b'{"name":"SettingBoilerEnable","parameter":{"identifier":"SteamBoiler","state":true}}\x00',
response=False,
)


Expand All @@ -57,9 +61,11 @@ async def test_bluetooth_set_temperature(
mock_bleak.write_gatt_char.assert_any_call( # type: ignore[attr-defined]
char_specifier=AUTH_CHARACTERISTIC,
data=b"dXNlcm5hbWU6c2VyaWFs@dG9rZW4=",
response=False,
)

mock_bleak.write_gatt_char.assert_called_with( # type: ignore[attr-defined]
char_specifier=SETTINGS_CHARACTERISTIC,
data=b'{"name":"SettingBoilerTarget","parameter":{"identifier":"SteamBoiler","value":131}}\x00',
response=False,
)

0 comments on commit ad6a4fc

Please sign in to comment.