Skip to content

Commit

Permalink
Air Humidifier: Handle poweroff exception on set_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Apr 10, 2019
1 parent feea7fc commit bafb3a0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click

from .click_common import command, format_output, EnumType
from .device import Device, DeviceInfo, DeviceException
from .device import Device, DeviceInfo, DeviceError, DeviceException

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -329,7 +329,14 @@ def off(self):
)
def set_mode(self, mode: OperationMode):
"""Set mode."""
return self.send("set_mode", [mode.value])
try:
return self.send("set_mode", [mode.value])
except DeviceError as error:
# {'code': -6011, 'message': 'device_poweroff'}
if error.code == -6011:
self.on()
return self.send("set_mode", [mode.value])
raise

@command(
click.argument("brightness", type=EnumType(LedBrightness, False)),
Expand Down

0 comments on commit bafb3a0

Please sign in to comment.