Skip to content

Commit

Permalink
Roborock: Add WiFi strength sensor
Browse files Browse the repository at this point in the history
I plan to use this to draw a WiFi signal strength map of my house
  • Loading branch information
SLaks committed Mar 19, 2024
1 parent 356c6c0 commit 0149b42
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def raw_command(self, command, parameters):
@command(
skip_autodetect=True,
)
def info(self, *, skip_cache=False) -> DeviceInfo:
def info(self, skip_cache=False) -> DeviceInfo:
"""Get (and cache) miIO protocol information from the device.
This includes information about connected wlan network, and hardware and
Expand Down
7 changes: 7 additions & 0 deletions miio/integrations/roborock/vacuum/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
CarpetModeStatus,
CleaningDetails,
CleaningSummary,
ConnectivityStatus,
ConsumableStatus,
DNDStatus,
MapList,
Expand Down Expand Up @@ -155,6 +156,7 @@ def __init__(
self._map_enum_cache = None
self._status_helper = UpdateHelper(self.vacuum_status)
self._status_helper.add_update_method("consumables", self.consumable_status)
self._status_helper.add_update_method("connectivity", self.connectivity_status)
self._status_helper.add_update_method("dnd_status", self.dnd_status)
self._status_helper.add_update_method("clean_history", self.clean_history)
self._status_helper.add_update_method("last_clean", self.last_clean_details)
Expand Down Expand Up @@ -620,6 +622,11 @@ def dnd_status(self) -> DNDStatus:
# 'start_hour': 22, 'end_hour': 8}], 'id': 1}
return DNDStatus(self.send("get_dnd_timer")[0])

@command()
def connectivity_status(self) -> ConnectivityStatus:
"""Returns WiFi connectivity information."""
return ConnectivityStatus(self.info(True)) # Skip cache

@command(
click.argument("start_hr", type=int),
click.argument("start_min", type=int),
Expand Down
18 changes: 18 additions & 0 deletions miio/integrations/roborock/vacuum/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pytz import BaseTzInfo

from miio.device import DeviceStatus
from miio.deviceinfo import DeviceInfo
from miio.devicestatus import sensor, setting
from miio.identifiers import VacuumId, VacuumState
from miio.utils import pretty_seconds, pretty_time
Expand Down Expand Up @@ -1058,3 +1059,20 @@ def enabled(self) -> bool:
def dry_time(self) -> timedelta:
"""Return mop dry time."""
return pretty_seconds(self.data["on"]["dry_time"])


class ConnectivityStatus(DeviceStatus):
def __init__(self, info: DeviceInfo) -> None:
self.info = info

@property
@sensor(
"Wifi Signal Strengh",
unit="dBm",
icon="mdi:wifi-strength-2", # TODO: Make this dynamic?
device_class="signal_strength",
entity_category="diagnostic",
)
def total_duration(self) -> timedelta:
"""Total cleaning duration."""
return self.info.accesspoint["rssi"]

0 comments on commit 0149b42

Please sign in to comment.