diff --git a/miio/airconditioningcompanion.py b/miio/airconditioningcompanion.py index 45d5073db..386850135 100644 --- a/miio/airconditioningcompanion.py +++ b/miio/airconditioningcompanion.py @@ -403,12 +403,12 @@ def send_command(self, command: str): @command( click.argument("model", type=str), - click.argument("power", type=EnumType(Power, False)), - click.argument("operation_mode", type=EnumType(OperationMode, False)), + click.argument("power", type=EnumType(Power)), + click.argument("operation_mode", type=EnumType(OperationMode)), click.argument("target_temperature", type=int), - click.argument("fan_speed", type=EnumType(FanSpeed, False)), - click.argument("swing_mode", type=EnumType(SwingMode, False)), - click.argument("led", type=EnumType(Led, False)), + click.argument("fan_speed", type=EnumType(FanSpeed)), + click.argument("swing_mode", type=EnumType(SwingMode)), + click.argument("led", type=EnumType(Led)), default_output=format_output("Sending a configuration to the air conditioner"), ) def send_configuration( diff --git a/miio/airdehumidifier.py b/miio/airdehumidifier.py index ea26511ae..5efdadd4f 100644 --- a/miio/airdehumidifier.py +++ b/miio/airdehumidifier.py @@ -253,7 +253,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -268,7 +268,7 @@ def set_mode(self, mode: OperationMode): raise @command( - click.argument("fan_speed", type=EnumType(FanSpeed, False)), + click.argument("fan_speed", type=EnumType(FanSpeed)), default_output=format_output("Setting fan level to {fan_level}"), ) def set_fan_speed(self, fan_speed: FanSpeed): diff --git a/miio/airfresh.py b/miio/airfresh.py index bb7913712..5c776b297 100644 --- a/miio/airfresh.py +++ b/miio/airfresh.py @@ -243,7 +243,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -264,7 +264,7 @@ def set_led(self, led: bool): return self.send("set_led", ["off"]) @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/airfresh_t2017.py b/miio/airfresh_t2017.py index a8b9b49d0..cbadfa37f 100644 --- a/miio/airfresh_t2017.py +++ b/miio/airfresh_t2017.py @@ -295,7 +295,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -316,7 +316,7 @@ def set_display(self, display: bool): return self.send("set_display", ["off"]) @command( - click.argument("orientation", type=EnumType(DisplayOrientation, False)), + click.argument("orientation", type=EnumType(DisplayOrientation)), default_output=format_output("Setting orientation to '{orientation.value}'"), ) def set_display_orientation(self, orientation: DisplayOrientation): @@ -324,7 +324,7 @@ def set_display_orientation(self, orientation: DisplayOrientation): return self.send("set_screen_direction", [orientation.value]) @command( - click.argument("level", type=EnumType(PtcLevel, False)), + click.argument("level", type=EnumType(PtcLevel)), default_output=format_output("Setting ptc level to '{level.value}'"), ) def set_ptc_level(self, level: PtcLevel): diff --git a/miio/airhumidifier.py b/miio/airhumidifier.py index bfdb26511..4ebc359f1 100644 --- a/miio/airhumidifier.py +++ b/miio/airhumidifier.py @@ -326,7 +326,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -341,7 +341,7 @@ def set_mode(self, mode: OperationMode): raise @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/airhumidifier_jsq.py b/miio/airhumidifier_jsq.py index 1b7bceb91..3e17ff429 100644 --- a/miio/airhumidifier_jsq.py +++ b/miio/airhumidifier_jsq.py @@ -229,7 +229,7 @@ def off(self): return self.send("set_start", [0]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -243,7 +243,7 @@ def set_mode(self, mode: OperationMode): return self.send("set_mode", [value]) @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/airhumidifier_miot.py b/miio/airhumidifier_miot.py index 7da45f99a..727044da7 100644 --- a/miio/airhumidifier_miot.py +++ b/miio/airhumidifier_miot.py @@ -326,7 +326,7 @@ def set_target_humidity(self, humidity: int): return self.set_property("target_humidity", humidity) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -334,7 +334,7 @@ def set_mode(self, mode: OperationMode): return self.set_property("mode", mode.value) @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/airhumidifier_mjjsq.py b/miio/airhumidifier_mjjsq.py index aae48c301..c7f0d9a33 100644 --- a/miio/airhumidifier_mjjsq.py +++ b/miio/airhumidifier_mjjsq.py @@ -182,7 +182,7 @@ def off(self): return self.send("Set_OnOff", [0]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): diff --git a/miio/airpurifier.py b/miio/airpurifier.py index 143e81ad1..cd7d360d8 100644 --- a/miio/airpurifier.py +++ b/miio/airpurifier.py @@ -424,7 +424,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -447,7 +447,7 @@ def set_favorite_level(self, level: int): return self.send("set_level_favorite", [level]) # 0 ... 17 @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/airpurifier_miot.py b/miio/airpurifier_miot.py index 861298173..2e3a16a97 100644 --- a/miio/airpurifier_miot.py +++ b/miio/airpurifier_miot.py @@ -348,7 +348,7 @@ def set_volume(self, volume: int): return self.set_property("buzzer_volume", volume) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -369,7 +369,7 @@ def set_favorite_level(self, level: int): return self.set_property("favorite_level", level) @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): diff --git a/miio/alarmclock.py b/miio/alarmclock.py index c72b9640e..ab4a9a7bb 100644 --- a/miio/alarmclock.py +++ b/miio/alarmclock.py @@ -90,9 +90,7 @@ def clock_system(self) -> HourlySystem: """ return HourlySystem(self.send("get_hourly_system")[0]) - @command( - click.argument("brightness", type=EnumType(HourlySystem, casesensitive=False)) - ) + @command(click.argument("brightness", type=EnumType(HourlySystem))) def set_hourly_system(self, hs: HourlySystem): return self.send("set_hourly_system", [hs.value]) @@ -126,9 +124,7 @@ def set_volume(self, volume): @command( click.argument( - "alarm_type", - type=EnumType(AlarmType, casesensitive=False), - default=AlarmType.Alarm.name, + "alarm_type", type=EnumType(AlarmType), default=AlarmType.Alarm.name ) ) def get_ring(self, alarm_type: AlarmType): @@ -136,8 +132,8 @@ def get_ring(self, alarm_type: AlarmType): return RingTone(self.send("get_ring", [{"type": alarm_type.value}]).pop()) @command( - click.argument("alarm_type", type=EnumType(AlarmType, casesensitive=False)), - click.argument("tone", type=EnumType(Tone, casesensitive=False)), + click.argument("alarm_type", type=EnumType(AlarmType)), + click.argument("tone", type=EnumType(Tone)), ) def set_ring(self, alarm_type: AlarmType, ring: RingTone): """Set alarm tone. diff --git a/miio/chuangmi_camera.py b/miio/chuangmi_camera.py index 8f79d181d..97f3802ce 100644 --- a/miio/chuangmi_camera.py +++ b/miio/chuangmi_camera.py @@ -327,7 +327,7 @@ def night_mode_on(self): return self.send("set_night_mode", [2]) @command( - click.argument("direction", type=EnumType(Direction, False)), + click.argument("direction", type=EnumType(Direction)), default_output=format_output("Rotating to direction '{direction.name}'"), ) def rotate(self, direction: Direction): @@ -340,7 +340,7 @@ def alarm(self): return self.send("alarm_sound") @command( - click.argument("sensitivity", type=EnumType(MotionDetectionSensitivity, False)), + click.argument("sensitivity", type=EnumType(MotionDetectionSensitivity)), default_output=format_output("Setting motion sensitivity '{sensitivity.name}'"), ) def set_motion_sensitivity(self, sensitivity: MotionDetectionSensitivity): @@ -353,7 +353,7 @@ def set_motion_sensitivity(self, sensitivity: MotionDetectionSensitivity): ) @command( - click.argument("mode", type=EnumType(HomeMonitoringMode, False)), + click.argument("mode", type=EnumType(HomeMonitoringMode)), click.argument("start-hour", default=10), click.argument("start-minute", default=0), click.argument("end-hour", default=17), @@ -378,23 +378,21 @@ def set_home_monitoring_config( [mode, start_hour, start_minute, end_hour, end_minute, notify, interval], ) - @command(default_output=format_output("Clearing NAS directory"),) + @command(default_output=format_output("Clearing NAS directory")) def clear_nas_dir(self): """Clear NAS directory""" - return self.send("nas_clear_dir", [[]],) + return self.send("nas_clear_dir", [[]]) - @command(default_output=format_output("Getting NAS config info"),) + @command(default_output=format_output("Getting NAS config info")) def get_nas_config(self): """Get NAS config info""" - return self.send("nas_get_config", {},) + return self.send("nas_get_config", {}) @command( - click.argument("state", type=EnumType(NASState, False)), + click.argument("state", type=EnumType(NASState)), click.argument("share"), - click.argument("sync-interval", type=EnumType(NASSyncInterval, False)), - click.argument( - "video-retention-time", type=EnumType(NASVideoRetentionTime, False) - ), + click.argument("sync-interval", type=EnumType(NASSyncInterval)), + click.argument("video-retention-time", type=EnumType(NASVideoRetentionTime)), default_output=format_output("Setting NAS config to '{state.name}'"), ) def set_nas_config( diff --git a/miio/click_common.py b/miio/click_common.py index ed7196317..406ddc075 100644 --- a/miio/click_common.py +++ b/miio/click_common.py @@ -63,7 +63,7 @@ def __call__(self, *args, **kwargs): class EnumType(click.Choice): - def __init__(self, enumcls, casesensitive=True): + def __init__(self, enumcls, casesensitive=False): choices = enumcls.__members__ if not casesensitive: diff --git a/miio/fan.py b/miio/fan.py index 1c0cb8577..1ba44c3a2 100644 --- a/miio/fan.py +++ b/miio/fan.py @@ -455,7 +455,7 @@ def set_direct_speed(self, speed: int): return self.send("set_speed_level", [speed]) @command( - click.argument("direction", type=EnumType(MoveDirection, False)), + click.argument("direction", type=EnumType(MoveDirection)), default_output=format_output("Rotating the fan to the {direction}"), ) def set_rotate(self, direction: MoveDirection): @@ -489,7 +489,7 @@ def set_oscillate(self, oscillate: bool): return self.send("set_angle_enable", ["off"]) @command( - click.argument("brightness", type=EnumType(LedBrightness, False)), + click.argument("brightness", type=EnumType(LedBrightness)), default_output=format_output("Setting LED brightness to {brightness}"), ) def set_led_brightness(self, brightness: LedBrightness): @@ -663,7 +663,7 @@ def off(self): return self.send("s_power", [False]) @command( - click.argument("mode", type=EnumType(OperationMode, False)), + click.argument("mode", type=EnumType(OperationMode)), default_output=format_output("Setting mode to '{mode.value}'"), ) def set_mode(self, mode: OperationMode): @@ -761,7 +761,7 @@ def delay_off(self, minutes: int): return self.send("s_t_off", [minutes]) @command( - click.argument("direction", type=EnumType(MoveDirection, False)), + click.argument("direction", type=EnumType(MoveDirection)), default_output=format_output("Rotating the fan to the {direction}"), ) def set_rotate(self, direction: MoveDirection): diff --git a/miio/heater.py b/miio/heater.py index b0abc8b5e..81f1dc207 100644 --- a/miio/heater.py +++ b/miio/heater.py @@ -223,7 +223,7 @@ def set_target_temperature(self, temperature: int): return self.send("set_target_temperature", [temperature]) @command( - click.argument("brightness", type=EnumType(Brightness, False)), + click.argument("brightness", type=EnumType(Brightness)), default_output=format_output("Setting display brightness to {brightness}"), ) def set_brightness(self, brightness: Brightness): diff --git a/miio/philips_rwread.py b/miio/philips_rwread.py index 4485457fc..64148a7c2 100644 --- a/miio/philips_rwread.py +++ b/miio/philips_rwread.py @@ -202,7 +202,7 @@ def set_motion_detection(self, motion_detection: bool): return self.send("enable_flm", [int(motion_detection)]) @command( - click.argument("sensitivity", type=EnumType(MotionDetectionSensitivity, False)), + click.argument("sensitivity", type=EnumType(MotionDetectionSensitivity)), default_output=format_output( "Setting motion detection sensitivity to {sensitivity}" ), diff --git a/miio/powerstrip.py b/miio/powerstrip.py index 5e9316080..c7b9a293d 100644 --- a/miio/powerstrip.py +++ b/miio/powerstrip.py @@ -213,7 +213,7 @@ def off(self): return self.send("set_power", ["off"]) @command( - click.argument("mode", type=EnumType(PowerMode, False)), + click.argument("mode", type=EnumType(PowerMode)), default_output=format_output("Setting mode to {mode}"), ) def set_power_mode(self, mode: PowerMode): diff --git a/miio/toiletlid.py b/miio/toiletlid.py index 1e7355b62..b7a32afb7 100644 --- a/miio/toiletlid.py +++ b/miio/toiletlid.py @@ -130,7 +130,7 @@ def nozzle_clean(self): return self.send("nozzle_clean", ["on"]) @command( - click.argument("color", type=EnumType(AmbientLightColor, False)), + click.argument("color", type=EnumType(AmbientLightColor)), click.argument("xiaomi_id", type=str, default=""), default_output=format_output( "Set the ambient light to {color} color the next time you start it." diff --git a/miio/vacuum.py b/miio/vacuum.py index d7787207d..c7f251186 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -12,7 +12,13 @@ import pytz from appdirs import user_cache_dir -from .click_common import DeviceGroup, GlobalContextObject, LiteralParamType, command +from .click_common import ( + DeviceGroup, + EnumType, + GlobalContextObject, + LiteralParamType, + command, +) from .device import Device from .exceptions import DeviceException, DeviceInfoUnavailableException from .vacuumcontainers import ( @@ -666,7 +672,7 @@ def waterflow(self) -> WaterFlow: """Get water flow setting.""" return WaterFlow(self.send("get_water_box_custom_mode")[0]) - @command(click.argument("waterflow", type=WaterFlow)) + @command(click.argument("waterflow", type=EnumType(WaterFlow))) def set_waterflow(self, waterflow: WaterFlow): """Set water flow setting.""" return self.send("set_water_box_custom_mode", [waterflow.value]) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 897cb733b..2aafcf341 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -276,7 +276,7 @@ def pause(self): """Pause cleaning.""" self.send("set_mode_withroom", [0, 2, 0]) - @command(click.argument("speed", type=EnumType(ViomiVacuumSpeed, False))) + @command(click.argument("speed", type=EnumType(ViomiVacuumSpeed))) def set_fan_speed(self, speed: ViomiVacuumSpeed): """Set fanspeed [silent, standard, medium, turbo].""" self.send("set_suction", [speed.value]) @@ -292,7 +292,7 @@ def home(self): self.send("set_charge", [1]) @command( - click.argument("direction", type=EnumType(ViomiMovementDirection, False)), + click.argument("direction", type=EnumType(ViomiMovementDirection)), click.option( "--duration", type=float, @@ -308,12 +308,12 @@ def move(self, direction, duration=0.5): time.sleep(0.1) self.send("set_direction", [ViomiMovementDirection.Stop.value]) - @command(click.argument("mode", type=EnumType(ViomiMode, False))) + @command(click.argument("mode", type=EnumType(ViomiMode))) def clean_mode(self, mode): """Set the cleaning mode.""" self.send("set_mop", [mode.value]) - @command(click.argument("mop_mode", type=EnumType(ViomiMopMode, False))) + @command(click.argument("mop_mode", type=EnumType(ViomiMopMode))) def mop_mode(self, mop_mode): self.send("set_moproute", [mop_mode.value]) @@ -352,12 +352,12 @@ def set_dnd( [0 if disable else 1, start_hr, start_min, end_hr, end_min], ) - @command(click.argument("language", type=EnumType(ViomiLanguage, False))) + @command(click.argument("language", type=EnumType(ViomiLanguage))) def set_language(self, language: ViomiLanguage): """Set the device's audio language.""" return self.send("set_language", [language.value]) - @command(click.argument("state", type=EnumType(ViomiLedState, False))) + @command(click.argument("state", type=EnumType(ViomiLedState))) def led(self, state: ViomiLedState): """Switch the button leds on or off.""" return self.send("set_light", [state.value])