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

Roborock: Add WiFi signal strength sensor #1918

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(skip_cache=True))

@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 @@ -1062,3 +1063,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"]