Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EnumType default to incasesensitive for cli tool #790

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions miio/airdehumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airfresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions miio/airfresh_t2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -316,15 +316,15 @@ 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):
"""Set display orientation."""
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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airhumidifier_jsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airhumidifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ 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):
"""Set working mode."""
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):
Expand Down
2 changes: 1 addition & 1 deletion miio/airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions miio/airpurifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions miio/alarmclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -126,18 +124,16 @@ 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):
"""Get current ring tone settings."""
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.
Expand Down
22 changes: 10 additions & 12 deletions miio/chuangmi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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),
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion miio/click_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions miio/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion miio/heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion miio/philips_rwread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
),
Expand Down
2 changes: 1 addition & 1 deletion miio/powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion miio/toiletlid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
10 changes: 8 additions & 2 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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])
Expand Down
Loading