From d85d88f81166241fb0079065b7bca4b7923c5d54 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Tue, 9 Mar 2021 00:47:20 +0100 Subject: [PATCH] Report more specific exception when airdehumidifer is off * Also, fix incorrect variable use for cli * Fixes #960 --- miio/airdehumidifier.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/miio/airdehumidifier.py b/miio/airdehumidifier.py index caacd307f..093d32f0f 100644 --- a/miio/airdehumidifier.py +++ b/miio/airdehumidifier.py @@ -271,11 +271,19 @@ def set_mode(self, mode: OperationMode): @command( click.argument("fan_speed", type=EnumType(FanSpeed)), - default_output=format_output("Setting fan level to {fan_level}"), + default_output=format_output("Setting fan level to {fan_speed}"), ) def set_fan_speed(self, fan_speed: FanSpeed): """Set the fan speed.""" - return self.send("set_fan_level", [fan_speed.value]) + try: + return self.send("set_fan_level", [fan_speed.value]) + except DeviceError as ex: + if ex.code == -10000: + raise AirDehumidifierException( + "Unable to set fan speed, this can happen if device is turned off." + ) from ex + + raise @command( click.argument("led", type=bool),