diff --git a/pylamarzocco/clients/bluetooth.py b/pylamarzocco/clients/bluetooth.py index 1a018d4..40557c5 100644 --- a/pylamarzocco/clients/bluetooth.py +++ b/pylamarzocco/clients/bluetooth.py @@ -131,11 +131,19 @@ async def authenticate() -> None: base64.b64encode(user_bytes) + b"@" + base64.b64encode(token) ) + auth_characteristic = client.services.get_characteristic( + AUTH_CHARACTERISTIC + ) + if auth_characteristic is None: + raise BluetoothConnectionFailed( + f"Could not find auth characteristic {AUTH_CHARACTERISTIC} on machine." + ) + try: await client.write_gatt_char( - char_specifier=AUTH_CHARACTERISTIC, + char_specifier=auth_characteristic, data=auth_string, - response=False, + response=True, ) except (BleakError, TimeoutError) as e: raise BluetoothConnectionFailed( @@ -148,10 +156,18 @@ async def authenticate() -> None: "Sending bluetooth message: %s to %s", message, characteristic ) + settings_characteristic = client.services.get_characteristic( + SETTINGS_CHARACTERISTIC + ) + if settings_characteristic is None: + raise BluetoothConnectionFailed( + f"Could not find settings characteristic {SETTINGS_CHARACTERISTIC} on machine." + ) + await client.write_gatt_char( - char_specifier=characteristic, + char_specifier=settings_characteristic, data=message, - response=False, + response=True, ) async def _write_bluetooth_json_message( diff --git a/pyproject.toml b/pyproject.toml index 46b7ad4..5a17142 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pylamarzocco" -version = "1.4.5" +version = "1.4.6" license = { text = "MIT" } description = "A Python implementation of the new La Marzocco API" readme = "README.md" diff --git a/tests/conftest.py b/tests/conftest.py index 03ec488..1cd9afa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -161,4 +161,6 @@ def mock_bleak() -> Generator[AsyncMock, None, None]: """Mock BleakClient.""" with patch("pylamarzocco.clients.bluetooth.BleakClient") as bleak_client: aenter = bleak_client.return_value.__aenter__.return_value + aenter.services.get_characteristic = lambda uuid: uuid + yield aenter diff --git a/tests/test_bluetooth.py b/tests/test_bluetooth.py index 1a53fe0..605d0f1 100644 --- a/tests/test_bluetooth.py +++ b/tests/test_bluetooth.py @@ -21,13 +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, + response=True, ) 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, + response=True, ) @@ -41,13 +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, + response=True, ) 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, + response=True, ) @@ -61,11 +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, + response=True, ) 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, + response=True, )