Skip to content

Commit

Permalink
Use standard identifiers for roborock (#1729)
Browse files Browse the repository at this point in the history
Follow the new standard set in #1724

Co-authored-by: Teemu R. <tpr@iki.fi>
  • Loading branch information
starkillerOG and rytilahti committed Feb 11, 2023
1 parent b4b7f1a commit 2a33f41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions miio/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class VacuumId(StandardIdentifier):
Pause = "vacuum:pause-sweeping"
ReturnHome = "battery:start-charge"
Locate = "identify:identify"
Spot = "vacuum:spot-cleaning" # TODO: invented name

# Settings
FanSpeed = "vacuum:fan-speed" # TODO: invented name
Expand Down
15 changes: 8 additions & 7 deletions miio/integrations/roborock/vacuum/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from miio.device import Device, DeviceInfo
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
Expand Down Expand Up @@ -179,7 +180,7 @@ def start(self):
return self.send("app_start")

@command()
@action(name="Stop cleaning", type="vacuum")
@action(name="Stop cleaning", id=VacuumId.Stop)
def stop(self):
"""Stop cleaning.
Expand All @@ -189,19 +190,19 @@ def stop(self):
return self.send("app_stop")

@command()
@action(name="Spot cleaning", type="vacuum")
@action(name="Spot cleaning", id=VacuumId.Spot)
def spot(self):
"""Start spot cleaning."""
return self.send("app_spot")

@command()
@action(name="Pause cleaning", type="vacuum")
@action(name="Pause cleaning", id=VacuumId.Pause)
def pause(self):
"""Pause cleaning."""
return self.send("app_pause")

@command()
@action(name="Start cleaning", type="vacuum")
@action(name="Start cleaning", id=VacuumId.Start)
def resume_or_start(self):
"""A shortcut for resuming or starting cleaning."""
status = self.status()
Expand Down Expand Up @@ -254,7 +255,7 @@ def create_dummy_mac(addr):
return self._info

@command()
@action(name="Home", type="vacuum")
@action(name="Home", id=VacuumId.ReturnHome)
def home(self):
"""Stop cleaning and return home."""

Expand Down Expand Up @@ -545,7 +546,7 @@ def clean_details(self, id_: int) -> Optional[CleaningDetails]:
return res

@command()
@action(name="Find robot", type="vacuum")
@action(name="Find robot", id=VacuumId.Locate)
def find(self):
"""Find the robot."""
return self.send("find_me", [""])
Expand Down Expand Up @@ -723,7 +724,7 @@ def set_sound_volume(self, vol: int):
return self.send("change_sound_volume", [vol])

@command()
@action(name="Test sound volume", type="vacuum")
@action(name="Test sound volume")
def test_sound_volume(self):
"""Test current sound volume."""
return self.send("test_sound_volume")
Expand Down
6 changes: 4 additions & 2 deletions miio/integrations/roborock/vacuum/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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.utils import pretty_seconds, pretty_time

Expand Down Expand Up @@ -192,7 +193,7 @@ def state(self) -> str:
self.state_code, f"Unknown state (code: {self.state_code})"
)

@sensor("Vacuum state")
@sensor("Vacuum state", id=VacuumId.State)
def vacuum_state(self) -> VacuumState:
"""Return vacuum state."""
return STATE_CODE_TO_VACUUMSTATE.get(self.state_code, VacuumState.Unknown)
Expand All @@ -211,6 +212,7 @@ def error_code(self) -> int:
@property
@sensor(
"Error string",
id=VacuumId.ErrorMessage,
icon="mdi:alert",
entity_category="diagnostic",
enabled_default=False,
Expand Down Expand Up @@ -252,7 +254,7 @@ def dock_error(self) -> Optional[str]:
return "Definition missing for dock error %s" % self.dock_error_code

@property
@sensor("Battery", unit="%", device_class="battery", enabled_default=False)
@sensor("Battery", unit="%", id=VacuumId.Battery)
def battery(self) -> int:
"""Remaining battery in percentage."""
return int(self.data["battery"])
Expand Down

0 comments on commit 2a33f41

Please sign in to comment.