From 59e1603e15bffd3b493014be6d6b11efb65a9239 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Thu, 12 Aug 2021 19:50:57 +0200 Subject: [PATCH] airpurifier_miot: return OperationMode.Unknown if mode is unknown (#1111) --- miio/airpurifier_miot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/miio/airpurifier_miot.py b/miio/airpurifier_miot.py index 9e4442a39..1f082fa0f 100644 --- a/miio/airpurifier_miot.py +++ b/miio/airpurifier_miot.py @@ -73,6 +73,7 @@ class AirPurifierMiotException(DeviceException): class OperationMode(enum.Enum): + Unknown = -1 Auto = 0 Silent = 1 Favorite = 2 @@ -110,7 +111,12 @@ def aqi(self) -> int: @property def mode(self) -> OperationMode: """Current operation mode.""" - return OperationMode(self.data["mode"]) + mode = self.data["mode"] + try: + return OperationMode(mode) + except ValueError: + _LOGGER.debug("Unknown mode: %s", mode) + return OperationMode.Unknown @property def buzzer(self) -> Optional[bool]: