Skip to content

Commit

Permalink
Rework docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed May 23, 2022
1 parent c7ebce0 commit 372702a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions miio/integrations/vacuum/dreame/dreamevacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,15 @@ def set_fan_speed(self, speed: int):

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
"""Return available fan speed presets."""
fanspeeds_enum = _get_cleaning_mode_enum_class(self.model)
if not fanspeeds_enum:
return {}
return _enum_as_dict(fanspeeds_enum)

@command(click.argument("speed", type=int))
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed, see VacuumInterface for detailed description."""
"""Set fan speed preset speed."""
if speed_preset not in self.fan_speed_presets().values():
raise ValueError(
f"Invalid preset speed {speed_preset}, not in: {self.fan_speed_presets().values()}"
Expand Down
4 changes: 2 additions & 2 deletions miio/integrations/vacuum/mijia/g1vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,12 @@ def set_fan_speed(self, fan_speed: G1FanSpeed):

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
"""Return available fan speed presets."""
return {x.name: x.value for x in G1FanSpeed}

@command(click.argument("speed", type=int))
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed, see VacuumInterface for detailed description."""
"""Set fan speed preset speed."""
if speed_preset not in self.fan_speed_presets().values():
raise ValueError(
f"Invalid preset speed {speed_preset}, not in: {self.fan_speed_presets().values()}"
Expand Down
4 changes: 2 additions & 2 deletions miio/integrations/vacuum/roborock/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def fan_speed(self):

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
"""Return available fan speed presets."""

def _enum_as_dict(cls):
return {x.name: x.value for x in list(cls)}
Expand Down Expand Up @@ -654,7 +654,7 @@ def _enum_as_dict(cls):

@command(click.argument("speed", type=int))
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed, see VacuumInterface for detailed description."""
"""Set fan speed preset speed."""
if speed_preset not in self.fan_speed_presets().values():
raise ValueError(
f"Invalid preset speed {speed_preset}, not in: {self.fan_speed_presets().values()}"
Expand Down
4 changes: 2 additions & 2 deletions miio/integrations/vacuum/roidmi/roidmivacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ def set_fanspeed(self, fanspeed_mode: FanSpeed):

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
"""Return available fan speed presets."""
return {"Sweep": 0, "Silent": 1, "Basic": 2, "Strong": 3, "FullSpeed": 4}

@command(click.argument("speed", type=int))
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed, see VacuumInterface for detailed description."""
"""Set fan speed preset speed."""
if speed_preset not in self.fan_speed_presets().values():
raise ValueError(
f"Invalid preset speed {speed_preset}, not in: {self.fan_speed_presets().values()}"
Expand Down
9 changes: 2 additions & 7 deletions miio/integrations/vacuum/viomi/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,6 @@ def fanspeed(self) -> ViomiVacuumSpeed:
"""Current fan speed."""
return ViomiVacuumSpeed(self.data["suction_grade"])

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
return {x.name: x.value for x in list(ViomiVacuumSpeed)}

@property
def water_grade(self) -> ViomiWaterGrade:
"""Water grade."""
Expand Down Expand Up @@ -679,12 +674,12 @@ def set_fan_speed(self, speed: ViomiVacuumSpeed):

@command()
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets, see VacuumInterface for details."""
"""Return available fan speed presets."""
return {x.name: x.value for x in list(ViomiVacuumSpeed)}

@command(click.argument("speed", type=int))
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed, see VacuumInterface for detailed description."""
"""Set fan speed preset speed."""
if speed_preset not in self.fan_speed_presets().values():
raise ValueError(
f"Invalid preset speed {speed_preset}, not in: {self.fan_speed_presets().values()}"
Expand Down
13 changes: 6 additions & 7 deletions miio/interfaces/vacuuminterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import abstractmethod
from typing import Dict

# dictionary of predefined fan speed; see corresponding method for detailed description
# Dictionary of predefined fan speeds
FanspeedPresets = Dict[str, int]


Expand All @@ -25,23 +25,22 @@ def stop(self):
def pause(self):
"""Pause cleaning.
:raise RuntimeError: if the method is not supported for the device
:raises RuntimeError: if the method is not supported by the device
"""
raise RuntimeError("`pause` not supported")

@abstractmethod
def fan_speed_presets(self) -> FanspeedPresets:
"""Return available fan speed presets.
:returns: Dictionary where:
- key is name (identifier)
- value is integer representation; usable as argument for set_fan_speed_preset() method
The returned object is a dictionary where the key is user-readable name and the
value is input for :func:`set_fan_speed_preset()`.
"""

@abstractmethod
def set_fan_speed_preset(self, speed_preset: int) -> None:
"""Set fan speed preset speed.
:param speed_preset: integer value from fan_speed_presets() method
:raise ValueError: if argument is not recognized preset speed for the device
:param speed_preset: a value from :func:`fan_speed_presets()`
:raises ValueError: for invalid preset value
"""

0 comments on commit 372702a

Please sign in to comment.