diff --git a/miio/ihcooker.py b/miio/ihcooker.py index 9778a7142..9aa97720d 100644 --- a/miio/ihcooker.py +++ b/miio/ihcooker.py @@ -3,12 +3,13 @@ import logging import random import warnings -import crc16 from collections import defaultdict from typing import Dict, List, Optional, Union import click +import crc16 + from .click_common import command, format_output from .device import Device from .exceptions import DeviceException @@ -79,12 +80,14 @@ START_REMIND_ON_BIT_STRING = 64 START_REMIND_OFF_BIT_STRING = 190 + class IHCookerException(DeviceException): pass class StageMode(enum.Enum): """Mode for current stage of recipe.""" + FireMode = 0 TemperatureMode = 2 Unknown1 = 4 @@ -95,6 +98,7 @@ class StageMode(enum.Enum): class OperationMode(enum.Enum): """Global mode the induction cooker is currently in""" + Error = "error" Finish = "finish" Offline = "offline" @@ -112,6 +116,7 @@ class OperationMode(enum.Enum): class CookProfile: """Represents a recipe containing cooking time, 16 stages of temperature&timing settings and more.""" + def __init__(self, model, profile=None): self.model = model """Initialize a cooking profile from an existing one, or a new one.""" @@ -535,30 +540,30 @@ def firmware_version(self) -> int: def __repr__(self) -> str: s = ( - "" - % ( - self.mode, - self.recipe_name, - self.stage, - self.temperature, - self.target_temp, - # self.start_time, - # self.remaining, - # self.cooking_delayed, - self.wifi_led_setting, - self.hardware_version, - self.firmware_version, - ) + "" + % ( + self.mode, + self.recipe_name, + self.stage, + self.temperature, + self.target_temp, + # self.start_time, + # self.remaining, + # self.cooking_delayed, + self.wifi_led_setting, + self.hardware_version, + self.firmware_version, + ) ) return s @@ -569,12 +574,12 @@ class IHCooker(Device): Custom recipes can be build with the CookProfile class.""" def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, + self, + ip: str = None, + token: str = None, + start_id: int = 0, + debug: int = 0, + lazy_discover: bool = True, ) -> None: super().__init__(ip, token, start_id, debug, lazy_discover) self._model = None @@ -634,7 +639,7 @@ def status(self) -> IHCookerStatus: click.argument("skip_confirmation", type=bool), default_output=format_output("Cooking profile started"), ) - def start(self, profile: str, skip_confirmation=False): + def start(self, profile: Union[str, CookProfile], skip_confirmation=False): """Start cooking a profile. Please do not use skip_confirmation=True, as this is potentially unsafe.""" @@ -656,8 +661,8 @@ def stop(self): """Stop cooking.""" self.send("set_func", ["end"]) - @command(default_output=format_output("Cooking stopped")) - def stop(self, location): + @command(default_output=format_output("Recipe deleted")) + def delete_recipe(self, location): """Delete recipe at location [0,7]""" if location >= 8 or location < 0: raise IHCookerException("location %d must be in [0,7]." % location) @@ -682,7 +687,7 @@ def set_wifi_led(self, value: bool): default_output=format_output("Setting menu to {profile}"), ) def set_menu( - self, profile: Union[str, CookProfile], location: int, confirm_start=False + self, profile: Union[str, CookProfile], location: int, confirm_start=False ): """Updates one of the menu options with the profile. @@ -698,7 +703,7 @@ def set_menu( self.send("set_menu1", [profile.to_hex()]) - def _prepare_profile(self, profile): + def _prepare_profile(self, profile: Union[str, CookProfile]) -> CookProfile: if isinstance(profile, str): profile = CookProfile(self.model, profile) return profile diff --git a/poetry.lock b/poetry.lock index 0bd208bff..9500b28c5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -130,6 +130,14 @@ version = "5.3" [package.extras] toml = ["toml"] +[[package]] +category = "main" +description = "Library for calculating CRC16" +name = "crc16" +optional = false +python-versions = "*" +version = "0.1.1" + [[package]] category = "main" description = "croniter provides iteration for datetime object with cron like format" @@ -966,6 +974,15 @@ coverage = [ {file = "coverage-5.3-cp39-cp39-win_amd64.whl", hash = "sha256:47a11bdbd8ada9b7ee628596f9d97fbd3851bd9999d398e9436bd67376dbece7"}, {file = "coverage-5.3.tar.gz", hash = "sha256:280baa8ec489c4f542f8940f9c4c2181f0306a8ee1a54eceba071a449fb870a0"}, ] +crc16 = [ + {file = "crc16-0.1.1.tar.gz", hash = "sha256:c1f86aa0390f4baf07d2631b16b979580eae1d9a973a826ce45353a22ee8d396"}, + {file = "crc16-0.1.1.win32-py2.6.exe", hash = "sha256:eb47b9cec9818b684537d05552ff10404c92d9dcdd455156456b19e7423855bc"}, + {file = "crc16-0.1.1.win32-py2.7.exe", hash = "sha256:7998bb0cacb0005ba62f963540c0f7cb09e86b51f6b4e64ed5632f31a7266fa1"}, + {file = "crc16-0.1.1.win32-py3.1.exe", hash = "sha256:1439e3cc0244a4758aa2d40a31b062086c24f5602046ec2fa4356484c4b5a385"}, + {file = "crc16-0.1.1.win32-py3.2.exe", hash = "sha256:521643768ff000a7758bc1f1c5e1dc41ae64b42fa57c50e133ab083cfaf9b8f9"}, + {file = "crc16-0.1.1.win32-py3.3.exe", hash = "sha256:63db8577ce0e03b39f30071166c6667659124a65d7fcd38adffe6a34487ce6fb"}, + {file = "crc16-0.1.1.zip", hash = "sha256:1b9f697a93491ae42ed653c1e78ea25a33532afab87b513e6890975450271a01"}, +] croniter = [ {file = "croniter-0.3.34-py2.py3-none-any.whl", hash = "sha256:15597ef0639f8fbab09cbf8c277fa8c65c8b9dbe818c4b2212f95dbc09c6f287"}, {file = "croniter-0.3.34.tar.gz", hash = "sha256:7186b9b464f45cf3d3c83a18bc2344cc101d7b9fd35a05f2878437b14967e964"}, diff --git a/pyproject.toml b/pyproject.toml index 6f82a91f2..2f0a2f629 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ netifaces = "^0" android_backup = { version = "^0", optional = true } importlib_metadata = { version = "^1", markers = "python_version <= '3.7'" } croniter = "^0" +crc16 = "*" sphinx = { version = "^3", optional = true } sphinx_click = { version = "^2", optional = true }