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

Bump python-roborock to 0.36.0 #103465

Merged
merged 9 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class RoborockBinarySensorDescriptionMixin:
"""A class that describes binary sensor entities."""

value_fn: Callable[[DeviceProp], bool]
value_fn: Callable[[DeviceProp], bool | int | None]


@dataclass
Expand Down
18 changes: 10 additions & 8 deletions homeassistant/components/roborock/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
device: HomeDataDevice,
device_networking: NetworkInfo,
product_info: HomeDataProduct,
cloud_api: RoborockMqttClient | None = None,
cloud_api: RoborockMqttClient,
) -> None:
"""Initialize."""
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
Expand All @@ -44,7 +44,9 @@ def __init__(
DeviceProp(),
)
device_data = DeviceData(device, product_info.model, device_networking.ip)
self.api = RoborockLocalClient(device_data)
self.api: RoborockLocalClient | RoborockMqttClient = RoborockLocalClient(
device_data
)
self.cloud_api = cloud_api
self.device_info = DeviceInfo(
name=self.roborock_device_info.device.name,
Expand All @@ -59,18 +61,18 @@ def __init__(

async def verify_api(self) -> None:
"""Verify that the api is reachable. If it is not, switch clients."""
try:
await self.api.ping()
except RoborockException:
if isinstance(self.api, RoborockLocalClient):
if isinstance(self.api, RoborockLocalClient):
try:
await self.api.ping()
except RoborockException:
_LOGGER.warning(
"Using the cloud API for device %s. This is not recommended as it can lead to rate limiting. We recommend making your vacuum accessible by your Home Assistant instance",
self.roborock_device_info.device.duid,
)
# We use the cloud api if the local api fails to connect.
self.api = self.cloud_api
# Right now this should never be called if the cloud api is the primary api,
# but in the future if it is, a new else should be added.
# Right now this should never be called if the cloud api is the primary api,
# but in the future if it is, a new else should be added.

async def release(self) -> None:
"""Disconnect from API."""
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/roborock/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@

def get_cache(self, attribute: CacheableAttribute) -> AttributeCache:
"""Get an item from the api cache."""
return self._api.cache.get(attribute)
if attribute not in self._api.cache:
raise HomeAssistantError(

Check warning on line 40 in homeassistant/components/roborock/device.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/roborock/device.py#L40

Added line #L40 was not covered by tests
f"Attempted to get {attribute.name} from the cache - but it does not exist."
)
return self._api.cache[attribute]

async def send(
self,
Expand All @@ -45,7 +49,7 @@
) -> dict:
"""Send a command to a vacuum cleaner."""
try:
response = await self._api.send_command(command, params)
response: dict = await self._api.send_command(command, params)
except RoborockException as err:
raise HomeAssistantError(
f"Error while calling {command.name if isinstance(command, RoborockCommand) else command} with {params}"
Expand Down Expand Up @@ -80,15 +84,11 @@
def _device_status(self) -> Status:
"""Return the status of the device."""
data = self.coordinator.data
if data:
status = data.status
if status:
return status
return Status({})
return data.status

async def send(
self,
command: RoborockCommand,
command: RoborockCommand | str,
params: dict[str, Any] | list[Any] | int | None = None,
) -> dict:
"""Overloads normal send command but refreshes coordinator."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/roborock",
"iot_class": "local_polling",
"loggers": ["roborock"],
"requirements": ["python-roborock==0.35.0"]
"requirements": ["python-roborock==0.35.4"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def async_setup_entry(
# We need to check if this function is supported by the device.
results = await asyncio.gather(
*(
coordinator.api.cache.get(description.cache_key).async_value()
coordinator.api.get_from_cache(description.cache_key)
for coordinator, description in possible_entities
),
return_exceptions=True,
Expand Down
23 changes: 14 additions & 9 deletions homeassistant/components/roborock/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class RoborockSelectDescriptionMixin:
# The command that the select entity will send to the api.
api_command: RoborockCommand
# Gets the current value of the select entity.
value_fn: Callable[[Status], str]
value_fn: Callable[[Status], str | None]
# Gets all options of the select entity.
options_lambda: Callable[[Status], list[str]]
options_lambda: Callable[[Status], list[str] | None]
# Takes the value from the select entiy and converts it for the api.
parameter_lambda: Callable[[str, Status], list[int]]

Expand All @@ -43,21 +43,23 @@ class RoborockSelectDescription(
key="water_box_mode",
translation_key="mop_intensity",
api_command=RoborockCommand.SET_WATER_BOX_CUSTOM_MODE,
value_fn=lambda data: data.water_box_mode.name,
value_fn=lambda data: data.water_box_mode_name,
entity_category=EntityCategory.CONFIG,
options_lambda=lambda data: data.water_box_mode.keys()
if data.water_box_mode
if data.water_box_mode is not None
else None,
parameter_lambda=lambda key, status: [status.water_box_mode.as_dict().get(key)],
parameter_lambda=lambda key, status: [status.get_mop_intensity_code(key)],
),
RoborockSelectDescription(
key="mop_mode",
translation_key="mop_mode",
api_command=RoborockCommand.SET_MOP_MODE,
value_fn=lambda data: data.mop_mode.name,
value_fn=lambda data: data.mop_mode_name,
entity_category=EntityCategory.CONFIG,
options_lambda=lambda data: data.mop_mode.keys() if data.mop_mode else None,
parameter_lambda=lambda key, status: [status.mop_mode.as_dict().get(key)],
options_lambda=lambda data: data.mop_mode.keys()
if data.mop_mode is not None
else None,
parameter_lambda=lambda key, status: [status.get_mop_mode_code(key)],
),
]

Expand Down Expand Up @@ -99,7 +101,10 @@ def __init__(
"""Create a select entity."""
self.entity_description = entity_description
super().__init__(unique_id, coordinator)
self._attr_options = self.entity_description.options_lambda(self._device_status)
options = self.entity_description.options_lambda(self._device_status)
# We know options is not none as this object would not have been created if it wasn't.
assert options is not None
Lash-L marked this conversation as resolved.
Show resolved Hide resolved
self._attr_options = options

async def async_select_option(self, option: str) -> None:
"""Set the option."""
Expand Down
32 changes: 23 additions & 9 deletions homeassistant/components/roborock/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:brush",
device_class=SensorDeviceClass.DURATION,
translation_key="main_brush_time_left",
value_fn=lambda data: data.consumable.main_brush_time_left,
value_fn=lambda data: data.consumable.main_brush_time_left
if data.consumable is not None
else None,
edenhaus marked this conversation as resolved.
Show resolved Hide resolved
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescription(
Expand All @@ -74,7 +76,9 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:brush",
device_class=SensorDeviceClass.DURATION,
translation_key="side_brush_time_left",
value_fn=lambda data: data.consumable.side_brush_time_left,
value_fn=lambda data: data.consumable.side_brush_time_left
if data.consumable is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescription(
Expand All @@ -83,7 +87,9 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:air-filter",
device_class=SensorDeviceClass.DURATION,
translation_key="filter_time_left",
value_fn=lambda data: data.consumable.filter_time_left,
value_fn=lambda data: data.consumable.filter_time_left
if data.consumable is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescription(
Expand All @@ -92,15 +98,19 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:eye-outline",
device_class=SensorDeviceClass.DURATION,
translation_key="sensor_time_left",
value_fn=lambda data: data.consumable.sensor_time_left,
value_fn=lambda data: data.consumable.sensor_time_left
if data.consumable is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescription(
native_unit_of_measurement=UnitOfTime.SECONDS,
key="cleaning_time",
translation_key="cleaning_time",
device_class=SensorDeviceClass.DURATION,
value_fn=lambda data: data.status.clean_time,
value_fn=lambda data: data.status.clean_time
if data.consumable is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescription(
Expand All @@ -117,7 +127,7 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:information-outline",
device_class=SensorDeviceClass.ENUM,
translation_key="status",
value_fn=lambda data: data.status.state.name,
value_fn=lambda data: data.status.state_name,
entity_category=EntityCategory.DIAGNOSTIC,
options=RoborockStateCode.keys(),
),
Expand All @@ -142,7 +152,7 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
icon="mdi:alert-circle",
translation_key="vacuum_error",
device_class=SensorDeviceClass.ENUM,
value_fn=lambda data: data.status.error_code.name,
value_fn=lambda data: data.status.error_code_name,
entity_category=EntityCategory.DIAGNOSTIC,
options=RoborockErrorCode.keys(),
),
Expand All @@ -157,15 +167,19 @@ def _dock_error_value_fn(properties: DeviceProp) -> str | None:
key="last_clean_start",
translation_key="last_clean_start",
icon="mdi:clock-time-twelve",
value_fn=lambda data: data.last_clean_record.begin_datetime,
value_fn=lambda data: data.last_clean_record.begin_datetime
if data.last_clean_record is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.TIMESTAMP,
),
RoborockSensorDescription(
key="last_clean_end",
translation_key="last_clean_end",
icon="mdi:clock-time-twelve",
value_fn=lambda data: data.last_clean_record.end_datetime,
value_fn=lambda data: data.last_clean_record.end_datetime
if data.last_clean_record is not None
else None,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.TIMESTAMP,
),
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def async_setup_entry(
# We need to check if this function is supported by the device.
results = await asyncio.gather(
*(
coordinator.api.cache.get(description.cache_key).async_value()
coordinator.api.get_from_cache(description.cache_key)
for coordinator, description in possible_entities
),
return_exceptions=True,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def async_setup_entry(
# We need to check if this function is supported by the device.
results = await asyncio.gather(
*(
coordinator.api.cache.get(description.cache_key).async_value()
coordinator.api.get_from_cache(description.cache_key)
for coordinator, description in possible_entities
),
return_exceptions=True,
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/roborock/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def __init__(
"""Initialize a vacuum."""
StateVacuumEntity.__init__(self)
RoborockCoordinatedEntity.__init__(self, unique_id, coordinator)
self._attr_fan_speed_list = self._device_status.fan_power.keys()
self._attr_fan_speed_list = self._device_status.fan_power_options

@property
def state(self) -> str | None:
"""Return the status of the vacuum cleaner."""
assert self._device_status.state is not None
return STATE_CODE_TO_STATE.get(self._device_status.state)

@property
Expand All @@ -108,7 +109,7 @@ def battery_level(self) -> int | None:
@property
def fan_speed(self) -> str | None:
"""Return the fan speed of the vacuum cleaner."""
return self._device_status.fan_power.name
return self._device_status.fan_power_name

async def async_start(self) -> None:
"""Start the vacuum."""
Expand Down Expand Up @@ -138,7 +139,7 @@ async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
"""Set vacuum fan speed."""
await self.send(
RoborockCommand.SET_CUSTOM_MODE,
[self._device_status.fan_power.as_dict().get(fan_speed)],
[self._device_status.get_fan_speed_code(fan_speed)],
)

async def async_start_pause(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ python-qbittorrent==0.4.3
python-ripple-api==0.0.3

# homeassistant.components.roborock
python-roborock==0.35.0
python-roborock==0.35.4

# homeassistant.components.smarttub
python-smarttub==0.0.33
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ python-picnic-api==1.1.0
python-qbittorrent==0.4.3

# homeassistant.components.roborock
python-roborock==0.35.0
python-roborock==0.35.4

# homeassistant.components.smarttub
python-smarttub==0.0.33
Expand Down