Skip to content

Commit

Permalink
Remove {Light,Vacuum}Interfaces (#1743)
Browse files Browse the repository at this point in the history
This PR removes `LightInterface` (which was never part of a release) and
`VacuumInterface` (which was mostly used to enforce the method naming
inside the library).
  • Loading branch information
rytilahti authored Feb 21, 2023
1 parent eca56e1 commit 69a5ff9
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 259 deletions.
1 change: 0 additions & 1 deletion miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from miio.exceptions import DeviceError, DeviceException, UnsupportedFeatureException
from miio.miot_device import MiotDevice
from miio.deviceinfo import DeviceInfo
from miio.interfaces import VacuumInterface, LightInterface, ColorTemperatureRange

# isort: on

Expand Down
19 changes: 18 additions & 1 deletion miio/identifiers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Compat layer for homeassistant."""
from enum import Enum
from enum import Enum, auto


class StandardIdentifier(Enum):
Expand Down Expand Up @@ -48,3 +48,20 @@ class LightId(StandardIdentifier):
Brightness = "light:brightness"
ColorTemperature = "light:color-temperature"
Color = "light:color"


class VacuumState(Enum):
"""Vacuum state enum.
This offers a simplified API to the vacuum state.
# TODO: the interpretation of simplified state should be done downstream.
"""

Unknown = auto()
Cleaning = auto()
Returning = auto()
Idle = auto()
Docked = auto()
Paused = auto()
Error = auto()
5 changes: 2 additions & 3 deletions miio/integrations/dreame/vacuum/dreamevacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import click

from miio.click_common import command, format_output
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.miot_device import DeviceStatus as DeviceStatusContainer
from miio.miot_device import MiotDevice, MiotMapping
from miio.updater import OneShotServer
Expand Down Expand Up @@ -464,7 +463,7 @@ def is_water_box_carriage_attached(self) -> Optional[bool]:
return None


class DreameVacuum(MiotDevice, VacuumInterface):
class DreameVacuum(MiotDevice):
_mappings = MIOT_MAPPING

@command(
Expand Down Expand Up @@ -588,7 +587,7 @@ def set_fan_speed(self, speed: int):
return self.set_property("cleaning_mode", fanspeed.value)

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""
fanspeeds_enum = _get_cleaning_mode_enum_class(self.model)
if not fanspeeds_enum:
Expand Down
5 changes: 2 additions & 3 deletions miio/integrations/ijai/vacuum/pro2vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from miio.click_common import EnumType, command, format_output
from miio.devicestatus import sensor, setting
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.miot_device import DeviceStatus, MiotDevice

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -267,7 +266,7 @@ def current_language(self) -> str:
return self.data["current_language"]


class Pro2Vacuum(MiotDevice, VacuumInterface):
class Pro2Vacuum(MiotDevice):
"""Support for Mi Robot Vacuum-Mop 2 Pro (ijai.vacuum.v3)."""

_mappings = _MAPPINGS
Expand Down Expand Up @@ -308,7 +307,7 @@ def set_fan_speed(self, fan_speed: FanSpeedMode):
return self.set_property("fan_speed", fan_speed)

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""
return _enum_as_dict(FanSpeedMode)

Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/mijia/vacuum/g1vacuum.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from datetime import timedelta
from enum import Enum
from typing import Dict

import click

from miio.click_common import EnumType, command, format_output
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.miot_device import DeviceStatus, MiotDevice

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -279,7 +279,7 @@ def total_clean_time(self) -> timedelta:
return timedelta(hours=self.data["total_clean_area"])


class G1Vacuum(MiotDevice, VacuumInterface):
class G1Vacuum(MiotDevice):
"""Support for G1 vacuum (G1, mijia.vacuum.v2)."""

_mappings = MIOT_MAPPING
Expand Down Expand Up @@ -379,7 +379,7 @@ def set_fan_speed(self, fan_speed: G1FanSpeed):
return self.set_property("fan_speed", fan_speed.value)

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""
return {x.name: x.value for x in G1FanSpeed}

Expand Down
7 changes: 3 additions & 4 deletions miio/integrations/roborock/vacuum/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pathlib
import time
from enum import Enum
from typing import Any, List, Optional, Type
from typing import Any, Dict, List, Optional, Type

import click
import pytz
Expand All @@ -25,7 +25,6 @@
from miio.devicestatus import DeviceStatus, action
from miio.exceptions import DeviceInfoUnavailableException, UnsupportedFeatureException
from miio.identifiers import VacuumId
from miio.interfaces import FanspeedPresets, VacuumInterface

from .updatehelper import UpdateHelper
from .vacuum_enums import (
Expand Down Expand Up @@ -123,7 +122,7 @@
]


class RoborockVacuum(Device, VacuumInterface):
class RoborockVacuum(Device):
"""Main class for roborock vacuums (roborock.vacuum.*)."""

_supported_models = SUPPORTED_MODELS
Expand Down Expand Up @@ -649,7 +648,7 @@ def fan_speed(self):
return self.send("get_custom_mode")[0]

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""

def _enum_as_dict(cls):
Expand Down
5 changes: 2 additions & 3 deletions miio/integrations/roborock/vacuum/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from miio.device import DeviceStatus
from miio.devicestatus import sensor, setting
from miio.identifiers import VacuumId
from miio.interfaces.vacuuminterface import VacuumDeviceStatus, VacuumState
from miio.identifiers import VacuumId, VacuumState
from miio.utils import pretty_seconds, pretty_time

from .vacuum_enums import MopIntensity, MopMode
Expand Down Expand Up @@ -134,7 +133,7 @@ def map_name_dict(self) -> Dict[str, int]:
return self._map_name_dict


class VacuumStatus(VacuumDeviceStatus):
class VacuumStatus(DeviceStatus):
"""Container for status reports from the vacuum."""

def __init__(self, data: Dict[str, Any]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/roidmi/vacuum/roidmivacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import math
from datetime import timedelta
from enum import Enum
from typing import Dict

import click

from miio.click_common import EnumType, command
from miio.integrations.roborock.vacuum.vacuumcontainers import ( # TODO: remove roborock import
DNDStatus,
)
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.miot_device import DeviceStatus, MiotDevice, MiotMapping

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -548,7 +548,7 @@ def sensor_dirty_left(self) -> timedelta:
return timedelta(minutes=self.data["sensor_dirty_time_left_minutes"])


class RoidmiVacuumMiot(MiotDevice, VacuumInterface):
class RoidmiVacuumMiot(MiotDevice):
"""Interface for Vacuum Eve Plus (roidmi.vacuum.v60)"""

_mappings = _MAPPINGS
Expand Down Expand Up @@ -651,7 +651,7 @@ def set_fanspeed(self, fanspeed_mode: FanSpeed):
return self.set_property("fanspeed_mode", fanspeed_mode.value)

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""
return {"Sweep": 0, "Silent": 1, "Basic": 2, "Strong": 3, "FullSpeed": 4}

Expand Down
12 changes: 5 additions & 7 deletions miio/integrations/viomi/vacuum/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@

from miio.click_common import EnumType, command
from miio.device import Device
from miio.devicestatus import action, sensor, setting
from miio.devicestatus import DeviceStatus, action, sensor, setting
from miio.exceptions import DeviceException
from miio.identifiers import VacuumId
from miio.identifiers import VacuumId, VacuumState
from miio.integrations.roborock.vacuum.vacuumcontainers import ( # TODO: remove roborock import
ConsumableStatus,
DNDStatus,
)
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.interfaces.vacuuminterface import VacuumDeviceStatus, VacuumState
from miio.utils import pretty_seconds

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -270,7 +268,7 @@ class ViomiEdgeState(Enum):
Unknown2 = 5


class ViomiVacuumStatus(VacuumDeviceStatus):
class ViomiVacuumStatus(DeviceStatus):
def __init__(self, data):
"""Vacuum status container.
Expand Down Expand Up @@ -582,7 +580,7 @@ def _get_rooms_from_schedules(schedules: List[str]) -> Tuple[bool, Dict]:
return scheduled_found, rooms


class ViomiVacuum(Device, VacuumInterface):
class ViomiVacuum(Device):
"""Interface for Viomi vacuums (viomi.vacuum.v7)."""

_supported_models = SUPPORTED_MODELS
Expand Down Expand Up @@ -794,7 +792,7 @@ def set_fan_speed(self, speed: ViomiVacuumSpeed):
self.send("set_suction", [speed.value])

@command()
def fan_speed_presets(self) -> FanspeedPresets:
def fan_speed_presets(self) -> Dict[str, int]:
"""Return available fan speed presets."""
return {x.name: x.value for x in list(ViomiVacuumSpeed)}

Expand Down
8 changes: 4 additions & 4 deletions miio/integrations/yeelight/light/spec_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import attr
import yaml

from miio import ColorTemperatureRange
from miio.descriptors import ValidSettingRange

_LOGGER = logging.getLogger(__name__)

Expand All @@ -18,7 +18,7 @@ class YeelightSubLightType(IntEnum):

@attr.s(auto_attribs=True)
class YeelightLampInfo:
color_temp: ColorTemperatureRange
color_temp: ValidSettingRange
supports_color: bool


Expand All @@ -43,14 +43,14 @@ def _parse_specs_yaml(self):
for key, value in models.items():
lamps = {
YeelightSubLightType.Main: YeelightLampInfo(
ColorTemperatureRange(*value["color_temp"]),
ValidSettingRange(*value["color_temp"]),
value["supports_color"],
)
}

if "background" in value:
lamps[YeelightSubLightType.Background] = YeelightLampInfo(
ColorTemperatureRange(*value["background"]["color_temp"]),
ValidSettingRange(*value["background"]["color_temp"]),
value["background"]["supports_color"],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from ..spec_helper import (
ColorTemperatureRange,
YeelightSpecHelper,
YeelightSubLightType,
)
from miio.descriptors import ValidSettingRange

from ..spec_helper import YeelightSpecHelper, YeelightSubLightType


def test_get_model_info():
spec_helper = YeelightSpecHelper()
model_info = spec_helper.get_model_info("yeelink.light.bslamp1")
assert model_info.model == "yeelink.light.bslamp1"
assert model_info.night_light is False
assert model_info.lamps[
YeelightSubLightType.Main
].color_temp == ColorTemperatureRange(1700, 6500)
assert model_info.lamps[YeelightSubLightType.Main].color_temp == ValidSettingRange(
1700, 6500
)
assert model_info.lamps[YeelightSubLightType.Main].supports_color is True
assert YeelightSubLightType.Background not in model_info.lamps

Expand All @@ -22,8 +20,8 @@ def test_get_unknown_model_info():
model_info = spec_helper.get_model_info("notreal")
assert model_info.model == "yeelink.light.*"
assert model_info.night_light is False
assert model_info.lamps[
YeelightSubLightType.Main
].color_temp == ColorTemperatureRange(1700, 6500)
assert model_info.lamps[YeelightSubLightType.Main].color_temp == ValidSettingRange(
1700, 6500
)
assert model_info.lamps[YeelightSubLightType.Main].supports_color is False
assert YeelightSubLightType.Background not in model_info.lamps
12 changes: 5 additions & 7 deletions miio/integrations/yeelight/light/yeelight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import click

from miio import LightInterface
from miio.click_common import command, format_output
from miio.descriptors import (
NumberSettingDescriptor,
Expand Down Expand Up @@ -283,7 +282,7 @@ def lights(self) -> List[YeelightSubLight]:
return sub_lights


class Yeelight(Device, LightInterface):
class Yeelight(Device):
"""A rudimentary support for Yeelight bulbs.
The API is the same as defined in
Expand Down Expand Up @@ -364,8 +363,8 @@ def settings(self) -> Dict[str, SettingDescriptor]:
# TODO: unclear semantics on settings, as making changes here will affect other instances of the class...
settings = super().settings().copy()
ct = self._light_info.color_temp
if ct.min != ct.max:
_LOGGER.info("Got ct for %s: %s", self.model, ct)
if ct.min_value != ct.max_value:
_LOGGER.debug("Got ct for %s: %s", self.model, ct)
settings[LightId.ColorTemperature.value] = NumberSettingDescriptor(
name="Color temperature",
id=LightId.ColorTemperature.value,
Expand All @@ -377,7 +376,7 @@ def settings(self) -> Dict[str, SettingDescriptor]:
unit="kelvin",
)
if self._light_info.supports_color:
_LOGGER.info("Got color for %s", self.model)
_LOGGER.debug("Got color for %s", self.model)
settings[LightId.Color.value] = NumberSettingDescriptor(
name="Color",
id=LightId.Color.value,
Expand All @@ -393,8 +392,7 @@ def settings(self) -> Dict[str, SettingDescriptor]:
@property
def color_temperature_range(self) -> ValidSettingRange:
"""Return supported color temperature range."""
temps = self._light_info.color_temp
return ValidSettingRange(min_value=temps[0], max_value=temps[1])
return self._light_info.color_temp

@command(
click.option("--transition", type=int, required=False, default=0),
Expand Down
11 changes: 0 additions & 11 deletions miio/interfaces/__init__.py

This file was deleted.

Loading

0 comments on commit 69a5ff9

Please sign in to comment.