Skip to content

Commit

Permalink
rename keep warm setting for multi cooker; lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sschirr committed Mar 30, 2024
1 parent ad8be3c commit fd16ea0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
38 changes: 22 additions & 16 deletions miio/integrations/chunmi/cooker_multi/cooker_multi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import enum
import logging
import math
Expand All @@ -6,13 +7,11 @@

import click
import crcmod
import datetime

from miio.click_common import command, format_output
from miio.device import Device, DeviceStatus
from miio.devicestatus import sensor


_LOGGER = logging.getLogger(__name__)

MODEL_MULTI = "chunmi.cooker.eh1"
Expand Down Expand Up @@ -125,7 +124,9 @@ def __str__(self) -> str:
class MultiCookerProfile:
"""This class can be used to modify and validate an existing cooking profile."""

def __init__(self, profile_hex: str, duration: int, schedule: int, akw: bool):
def __init__(
self, profile_hex: str, duration: int, schedule: int, auto_keep_warm: bool
):
if len(profile_hex) < 5:
raise ValueError("Invalid profile")

Check warning on line 131 in miio/integrations/chunmi/cooker_multi/cooker_multi.py

View check run for this annotation

Codecov / codecov/patch

miio/integrations/chunmi/cooker_multi/cooker_multi.py#L131

Added line #L131 was not covered by tests
else:
Expand All @@ -140,8 +141,8 @@ def __init__(self, profile_hex: str, duration: int, schedule: int, akw: bool):
if schedule is not None:
self.set_schedule_enabled(True)
self.set_schedule_duration(schedule)
if akw is not None:
self.set_akw_enabled(akw)
if auto_keep_warm is not None:
self.set_auto_keep_warm_enabled(auto_keep_warm)

def is_set_duration_allowed(self):
return (
Expand Down Expand Up @@ -192,10 +193,10 @@ def set_schedule_duration(self, duration):

self.update_checksum()

def is_akw_enabled(self):
def is_auto_keep_warm_enabled(self):
return (self.profile_bytes[15] & 0x80) == 0x80

Check warning on line 197 in miio/integrations/chunmi/cooker_multi/cooker_multi.py

View check run for this annotation

Codecov / codecov/patch

miio/integrations/chunmi/cooker_multi/cooker_multi.py#L197

Added line #L197 was not covered by tests

def set_akw_enabled(self, enabled):
def set_auto_keep_warm_enabled(self, enabled):
if enabled:
self.profile_bytes[15] |= 0x80
else:
Expand Down Expand Up @@ -261,10 +262,15 @@ def temperature(self) -> Optional[int]:

@property
@sensor("Cooking finish time")
def ready_at(self) -> datetime:
def ready_at(self) -> datetime.datetime:
"""Remaining minutes of the cooking process."""
return (datetime.datetime.now() + datetime.timedelta(0, int(self.data["t_left"] + (self.data["t_pre"]*60)))).replace(second=0, microsecond=0)

return (
datetime.datetime.now()
+ datetime.timedelta(
0, int(self.data["t_left"] + (self.data["t_pre"] * 60))
)
).replace(second=0, microsecond=0)

@property
@sensor("Cooking start delay")
def cooking_delayed(self) -> Optional[int]:
Expand Down Expand Up @@ -359,12 +365,12 @@ def status(self) -> CookerStatus:
click.argument("profile", type=str, required=True),
click.option("--duration", type=int, required=False),
click.option("--schedule", type=int, required=False),
click.option("--akw", type=bool, required=False),
click.option("--auto-keep-warm", type=bool, required=False),
default_output=format_output("Cooking profile started"),
)
def start(self, profile: str, duration: int, schedule: int, akw: bool):
def start(self, profile: str, duration: int, schedule: int, auto_keep_warm: bool):
"""Start cooking a profile."""
cookerProfile = MultiCookerProfile(profile, duration, schedule, akw)
cookerProfile = MultiCookerProfile(profile, duration, schedule, auto_keep_warm)
self.send("set_start", [cookerProfile.get_profile_hex()])

@command(default_output=format_output("Cooking stopped"))
Expand All @@ -376,12 +382,12 @@ def stop(self):
click.argument("profile", type=str),
click.option("--duration", type=int, required=False),
click.option("--schedule", type=int, required=False),
click.option("--akw", type=bool, required=False),
click.option("--auto-keep-warm", type=bool, required=False),
default_output=format_output("Setting menu to {profile}"),
)
def menu(self, profile: str, duration: int, schedule: int, akw: bool):
def menu(self, profile: str, duration: int, schedule: int, auto_keep_warm: bool):
"""Select one of the default(?) cooking profiles."""
cookerProfile = MultiCookerProfile(profile, duration, schedule, akw)
cookerProfile = MultiCookerProfile(profile, duration, schedule, auto_keep_warm)
self.send("set_menu", [cookerProfile.get_profile_hex()])

Check warning on line 391 in miio/integrations/chunmi/cooker_multi/cooker_multi.py

View check run for this annotation

Codecov / codecov/patch

miio/integrations/chunmi/cooker_multi/cooker_multi.py#L390-L391

Added lines #L390 - L391 were not covered by tests

@command(default_output=format_output("", "Temperature history: {result}\n"))
Expand Down
25 changes: 15 additions & 10 deletions miio/integrations/chunmi/cooker_multi/test_cooker_multi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import datetime
from unittest import TestCase

import pytest

import datetime

from miio.tests.dummies import DummyDevice

from .cooker_multi import MultiCooker, OperationMode
Expand All @@ -16,7 +15,7 @@
}

TEST_CASES = {
# Fine rice; Schedule 75; Akw True
# Fine rice; Schedule 75; auto-keep-warm True
"test_case_0": {
"expected_profile": "02010000000001e1010000000000818f0101050814000000002091827d7800050091822d781c0a0091823c781c1e0091ff827820ffff91828278000500ffff8278ffffff91828278000d00ff828778ff000091827d7800000091827d7800ffff91826078ff0100490366780701086c0078090301af540266780801086c00780a02023c5701667b0e010a71007a0d02ffff5701667b0f010a73007d0d032005000000000000000000000000000000b557",
"cooker_state": {
Expand All @@ -43,7 +42,7 @@
"boil": 0,
},
},
# Fine rice; Schedule 75; Akw False
# Fine rice; Schedule 75; auto-keep-warm False
"test_case_1": {
"expected_profile": "02010000000001e1010000000000810f0101050814000000002091827d7800050091822d781c0a0091823c781c1e0091ff827820ffff91828278000500ffff8278ffffff91828278000d00ff828778ff000091827d7800000091827d7800ffff91826078ff0100490366780701086c0078090301af540266780801086c00780a02023c5701667b0e010a71007a0d02ffff5701667b0f010a73007d0d03200500000000000000000000000000000049ee",
"cooker_state": {
Expand All @@ -70,7 +69,7 @@
"boil": 0,
},
},
# Quick rice; Schedule 75; Akw False
# Quick rice; Schedule 75; auto-keep-warm False
"test_case_2": {
"expected_profile": "02010100000002e1002800000000810f0101050614000000002091827d7800000091823c7820000091823c781c1e0091ff827820ffff91828278000500ffff8278ffffff91828278000d00ff828778ff000082827d7800000091827d7800ffff91826078ff0164490366780701086c007409030200540266780801086c00760a0202785701667b0e010a7100780a02ffff5701667b0f010a73007b0a0320050000000000000000000000000000005b07",
"cooker_state": {
Expand All @@ -97,7 +96,7 @@
"boil": 0,
},
},
# Congee; Akw False
# Congee; auto-keep-warm False
"test_case_3": {
"expected_profile": "02010200000003e2011e0400002800000101050614000000002091827d7800000091827d7800000091827d78001e0091ff877820ffff91827d78001e0091ff8278ffffff91828278001e0091828278060f0091827d7804000091827d7800000091827d780001f54e0255261802062a0482030002eb4e0255261802062a04820300032d4e0252261802062c04820501ffff4e0152241802062c048205012000000000000000000000000000000000605b",
"cooker_state": {
Expand Down Expand Up @@ -217,9 +216,11 @@ def test_case_0(self):
assert status.menu == "Fine Rice"
assert status.cooking_delayed == 75
assert status.keep_warm is True

# Total time should be 75min delay + 60min cooking time for "Fine rice"
assert status.ready_at == (datetime.datetime.now() + datetime.timedelta(0, (75+60)*60)).replace(second=0, microsecond=0)
assert status.ready_at == (
datetime.datetime.now() + datetime.timedelta(0, (75 + 60) * 60)
).replace(second=0, microsecond=0)
self.device.stop()

def test_case_1(self):
Expand All @@ -231,7 +232,9 @@ def test_case_1(self):
assert status.keep_warm is False

# Total time should be 75min delay + 60min cooking time for "Fine rice"
assert status.ready_at == (datetime.datetime.now() + datetime.timedelta(0, (75+60)*60)).replace(second=0, microsecond=0)
assert status.ready_at == (
datetime.datetime.now() + datetime.timedelta(0, (75 + 60) * 60)
).replace(second=0, microsecond=0)
self.device.stop()

def test_case_2(self):
Expand All @@ -243,7 +246,9 @@ def test_case_2(self):
assert status.keep_warm is False

# Total time should be 75min delay + 40min cooking time for "Quick rice"
assert status.ready_at == (datetime.datetime.now() + datetime.timedelta(0, (75+40)*60)).replace(second=0, microsecond=0)
assert status.ready_at == (
datetime.datetime.now() + datetime.timedelta(0, (75 + 40) * 60)
).replace(second=0, microsecond=0)
self.device.stop()

def test_case_3(self):
Expand Down

0 comments on commit fd16ea0

Please sign in to comment.