1
1
"""Test the LaMarzoccoMachine class."""
2
2
3
+ # pylint: disable=W0212
4
+
3
5
from unittest .mock import AsyncMock , patch
4
6
5
7
import pytest
6
8
from syrupy import SnapshotAssertion
9
+ from http import HTTPMethod
7
10
11
+ from lmcloud .client_bluetooth import LaMarzoccoBluetoothClient
8
12
from lmcloud .client_cloud import LaMarzoccoCloudClient
9
13
from lmcloud .client_local import LaMarzoccoLocalClient
10
14
from lmcloud .const import BoilerType , MachineModel , PhysicalKey , WeekDay
@@ -31,12 +35,7 @@ async def test_local_client(
31
35
) -> None :
32
36
"""Ensure that the local client delivers same result"""
33
37
34
- machine = await LaMarzoccoMachine .create (
35
- model = MachineModel .GS3_AV ,
36
- serial_number = MACHINE_SERIAL ,
37
- name = "MyMachine" ,
38
- local_client = local_machine_client ,
39
- )
38
+ machine = await init_machine (local_client = local_machine_client )
40
39
41
40
machine2 = await init_machine (cloud_client )
42
41
@@ -103,13 +102,7 @@ async def test_websocket_message(
103
102
snapshot : SnapshotAssertion ,
104
103
):
105
104
"""Test parsing of websocket messages."""
106
- machine = await LaMarzoccoMachine .create (
107
- model = MachineModel .GS3_AV ,
108
- serial_number = MACHINE_SERIAL ,
109
- name = "MyMachine" ,
110
- cloud_client = cloud_client ,
111
- local_client = local_machine_client ,
112
- )
105
+ machine = await init_machine (cloud_client , local_client = local_machine_client )
113
106
114
107
message = r'[{"Boilers":"[{\"id\":\"SteamBoiler\",\"isEnabled\":true,\"target\":131,\"current\":113},{\"id\":\"CoffeeBoiler1\",\"isEnabled\":true,\"target\":94,\"current\":81}]"}]'
115
108
machine .on_websocket_message_received (message )
@@ -118,3 +111,87 @@ async def test_websocket_message(
118
111
message = r'[{"BoilersTargetTemperature":"{\"SteamBoiler\":131,\"CoffeeBoiler1\":94}"},{"Boilers":"[{\"id\":\"SteamBoiler\",\"isEnabled\":true,\"target\":131,\"current\":50},{\"id\":\"CoffeeBoiler1\",\"isEnabled\":true,\"target\":94,\"current\":36}]"}]'
119
112
machine .on_websocket_message_received (message )
120
113
assert machine .config == snapshot
114
+
115
+
116
+ async def test_set_power (
117
+ cloud_client : LaMarzoccoCloudClient , bluetooth_client : LaMarzoccoBluetoothClient
118
+ ):
119
+ """Test setting the power."""
120
+ machine = await init_machine (cloud_client , bluetooth_client = bluetooth_client )
121
+
122
+ assert await machine .set_power (True )
123
+
124
+ bluetooth_client ._client .write_gatt_char .assert_called_once_with ( # type: ignore[attr-defined]
125
+ "050b7847-e12b-09a8-b04b-8e0922a9abab" ,
126
+ b'{"name":"MachineChangeMode","parameter":{"mode":"BrewingMode"}}\x00 ' ,
127
+ )
128
+ cloud_client ._oauth_client .request .assert_any_call ( # type: ignore[union-attr]
129
+ HTTPMethod .POST ,
130
+ "https://gw-lmz.lamarzocco.io/v1/home/machines/GS01234/status" ,
131
+ json = {"status" : "BrewingMode" },
132
+ )
133
+
134
+
135
+ async def test_set_steam (
136
+ cloud_client : LaMarzoccoCloudClient , bluetooth_client : LaMarzoccoBluetoothClient
137
+ ):
138
+ """Test setting the steam."""
139
+ machine = await init_machine (cloud_client , bluetooth_client = bluetooth_client )
140
+
141
+ assert await machine .set_steam (True )
142
+
143
+ bluetooth_client ._client .write_gatt_char .assert_called_once_with ( # type: ignore[attr-defined]
144
+ "050b7847-e12b-09a8-b04b-8e0922a9abab" ,
145
+ b'{"name":"SettingBoilerEnable","parameter":{"identifier":"SteamBoiler","state":true}}\x00 ' ,
146
+ )
147
+ cloud_client ._oauth_client .request .assert_any_call ( # type: ignore[union-attr]
148
+ HTTPMethod .POST ,
149
+ "https://gw-lmz.lamarzocco.io/v1/home/machines/GS01234/enable-boiler" ,
150
+ json = {"identifier" : "SteamBoiler" , "state" : True },
151
+ )
152
+
153
+
154
+ async def test_set_temperature (
155
+ cloud_client : LaMarzoccoCloudClient , bluetooth_client : LaMarzoccoBluetoothClient
156
+ ):
157
+ """Test setting temperature."""
158
+ machine = await init_machine (cloud_client , bluetooth_client = bluetooth_client )
159
+
160
+ assert await machine .set_temp (BoilerType .STEAM , 131 )
161
+
162
+ bluetooth_client ._client .write_gatt_char .assert_called_once_with ( # type: ignore[attr-defined]
163
+ "050b7847-e12b-09a8-b04b-8e0922a9abab" ,
164
+ b'{"name":"SettingBoilerTarget","parameter":{"identifier":"SteamBoiler","value":131}}\x00 ' ,
165
+ )
166
+ cloud_client ._oauth_client .request .assert_any_call ( # type: ignore[union-attr]
167
+ HTTPMethod .POST ,
168
+ "https://gw-lmz.lamarzocco.io/v1/home/machines/GS01234/target-boiler" ,
169
+ json = {"identifier" : "SteamBoiler" , "value" : 131 },
170
+ )
171
+
172
+
173
+ async def test_set_prebrew_time (cloud_client : LaMarzoccoCloudClient ):
174
+ """Test setting prebrew time."""
175
+ machine = await init_machine (
176
+ cloud_client ,
177
+ )
178
+
179
+ assert await machine .set_prebrew_time (1.0 , 3.5 )
180
+
181
+ cloud_client ._oauth_client .request .assert_any_call ( # type: ignore[union-attr]
182
+ HTTPMethod .POST ,
183
+ "https://gw-lmz.lamarzocco.io/v1/home/machines/GS01234/setting-preinfusion" ,
184
+ json = {
185
+ "button" : "DoseA" ,
186
+ "group" : "Group1" ,
187
+ "holdTimeMs" : 3500 ,
188
+ "wetTimeMs" : 1000 ,
189
+ },
190
+ )
191
+
192
+ assert await machine .set_preinfusion_time (4.5 )
193
+ cloud_client ._oauth_client .request .assert_any_call ( # type: ignore[union-attr]
194
+ HTTPMethod .POST ,
195
+ "https://gw-lmz.lamarzocco.io/v1/home/machines/GS01234/setting-preinfusion" ,
196
+ json = {"button" : "DoseA" , "group" : "Group1" , "holdTimeMs" : 4500 , "wetTimeMs" : 0 },
197
+ )
0 commit comments