From 9c8d2605a80796b26f70f9948266b55c48a4c88e Mon Sep 17 00:00:00 2001 From: Alex X Date: Sat, 30 Dec 2023 08:44:35 +0300 Subject: [PATCH] Add support grinder ratio for GIGA 5 --- custom_components/jura/core/device.py | 2 +- tests/test_misc.py | 149 +++++++++++++++++++++++++- 2 files changed, 145 insertions(+), 6 deletions(-) diff --git a/custom_components/jura/core/device.py b/custom_components/jura/core/device.py index 6566aae..c498b16 100644 --- a/custom_components/jura/core/device.py +++ b/custom_components/jura/core/device.py @@ -10,7 +10,7 @@ SELECTS = [ "product", # 1 - # "grinder_ratio", # 2 + "grinder_ratio", # 2 "coffee_strength", # 3 "temperature", # 7 ] diff --git a/tests/test_misc.py b/tests/test_misc.py index 0bd0a0a..a93c2d0 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -5,16 +5,16 @@ from custom_components.jura.select import JuraSelect -def make_device() -> Device: +def make_device(adv: bytes) -> Device: ble = BLEDevice("", None, None, 0) - adv = AdvertisementData(None, {171: b"*\x05\x08\x03\xfb;"}, {}, [], None, 0, ()) + adv = AdvertisementData(None, {171: adv}, {}, [], None, 0, ()) device = Device("Jura", ble, adv) device.client.ping = lambda *args: None return device -def test_device(): - device = make_device() +def test_device_e8(): + device = make_device(b"*\x05\x08\x03\xfb;") assert device.model == "E8 (EB)" # Check GUI elements list @@ -76,8 +76,100 @@ def test_device(): assert cmd.hex() == "000400080c000e0100000000000000000000" +def test_device_d4(): + device = make_device(b"*\x05\x08\x03u;") + assert device.model == "D4" + + # Check GUI elements list + assert device.selects() == ["product", "coffee_strength", "temperature"] + assert device.numbers() == ["water_amount", "bypass"] + + # Check products list + attr = device.attribute("product") + assert attr == { + "default": None, + "options": [ + "Espresso", + "Coffee", + "2 Espressi", + "2 Coffee", + "Ristretto (only JOE)", + "Cafe Barista (only JOE)", + "Barista Lungo (only JOE)", + "Espresso Doppio (only JOE)", + "2 Ristretti (only JOE)", + ], + } + + +def test_device_giga5(): + # https://github.com/AlexxIT/Jura/issues/10 + device = make_device(b"*\x05\x08\x03=5") + assert device.model == "GIGA 5" + + assert device.selects() == [ + "product", + "grinder_ratio", + "coffee_strength", + "temperature", + ] + assert device.numbers() == ["water_amount", "milk_amount", "milk_foam_amount"] + + # Check products list + attr = device.attribute("product") + assert attr == { + "default": None, + "options": [ + "Ristretto", + "Espresso", + "Coffee", + "Cappuccino", + "Milkcoffee", + "Espresso Macchiato", + "Latte Macchiato", + "Milk Foam", + "Milk Portion", + "Pot", + "Hotwater Portion", + "2 Ristretti", + "2 Espressi", + "2 Coffee", + "2 Cappuccini", + "2 Milkcoffee", + "2 Espresso Macchiati", + "2 Latte Macchiati", + "2 Milk Foam", + "2 Portion Milk", + ], + } + + # Select product + device.select_option("product", "Coffee") + + cmd = device.command() + assert cmd.hex() == "000302031400000100000000000000000000" + + attr = device.attribute("coffee_strength") + assert attr == { + "default": "Normal", + "options": ["XMild", "Mild", "Normal", "Strong", "XStrong"], + } + + attr = device.attribute("grinder_ratio") + assert attr == { + "default": "50_50", + "options": ["100_0", "75_25", "50_50", "25_75", "0_100"], + } + + attr = device.attribute("water_amount") + assert attr == {"max": 240, "min": 25, "step": 5, "value": 100} + + attr = device.attribute("temperature") + assert attr == {"default": "Normal", "options": ["Low", "Normal", "High"]} + + def test_coffee_strength(): - device = make_device() + device = make_device(b"*\x05\x08\x03\xfb;") select = JuraSelect(device, "coffee_strength") assert select.name == "Jura Coffee Strength" @@ -104,3 +196,50 @@ def test_encdec(): b = bytes.fromhex("77ea3dd38981dadba32bfa98a4a3faab45fd") b = encdec(b, 0x2A) assert b.hex() == "2a0400080c000e010001000000000000062a" + + +def test_status_key2A(): + b = bytes.fromhex("77E13ED68882D3D7A323FA98A4A3FAAB4756A629") + b = encdec(b, 0x2A) + assert b.hex() == "2a00040000040008000000000000000000000007" + + # no bottom tray + b = bytes.fromhex("77D23DD68882D3D7A323FA98A4A3FAAB4756A625") + b = encdec(b, 0x2A) + assert b.hex() == "2a88000000040008000000000000000000000006" + + # no water tray + b = bytes.fromhex("77113DD68882D3D7A323FA98A4A3FAAB4756A625") + b = encdec(b, 0x2A) + assert b.hex() == "2a40000000040008000000000000000000000006" + + # no water tray + remove water from bottom tray + b = bytes.fromhex("77913DD6888BD3D7A323FA98A4A3FAAB4756A625") + b = encdec(b, 0x2A) + assert b.hex() == "2a500000000c0008000000000000000000000006" + + +def test_status_key00(): + b = bytes.fromhex("14444CC623152D9ABFE772ED1B3F65136B888DDC") + b = encdec(b, 0) + assert b.hex() == "0000000000000000000000000000000000000004" + + # coffee trash + b = bytes.fromhex("14A44CC623153D94BFE772ED1B3F65136B888DD2") + b = encdec(b, 0) + assert b.hex() == "0020000000004008000000000000000000000006" + + # zero water + b = bytes.fromhex("14044CC623153D94BFE772ED1B3F65136B888DDC") + b = encdec(b, 0) + assert b.hex() == "0040000000004008000000000000000000000004" + + # cleaning milk and usual cleaning + b = bytes.fromhex("144448C623753D94BFE772ED1B3F65136B888DDC") + b = encdec(b, 0) + assert b.hex() == "0000040000204008000000000000000000000004" + + # usual cleaning + b = bytes.fromhex("144448C623752D94BFE772ED1B3F65136B888DD2") + b = encdec(b, 0) + assert b.hex() == "0000040000200008000000000000000000000006"