Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions custom_components/dreame_vacuum/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ async def async_step_connect(self, user_input: dict[str, Any] | None = None) ->
async def async_step_local(
self,
user_input: dict[str, Any] | None = None,
errors: dict[str, Any] | None = {},
errors: dict[str, Any] | None = None,
error: str | None = None,
) -> FlowResult:
"""Handle the initial step."""
if errors is None:
errors = {}
if user_input is not None:
self._async_abort_entries_match(user_input)

Expand Down Expand Up @@ -322,9 +324,11 @@ async def async_step_login(self, error=None):
return await self.async_step_local(error=error)

async def async_step_mi(
self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = {}, error: str | None = None
self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = None, error: str | None = None
) -> FlowResult:
"""Configure a dreame vacuum device through the Miio Cloud."""
if errors is None:
errors = {}

description_placeholders = {}
if user_input is not None:
Expand Down Expand Up @@ -379,7 +383,9 @@ async def async_step_mi(
errors=errors,
)

async def async_step_2fa(self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = {}):
async def async_step_2fa(self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = None):
if errors is None:
errors = {}
if self.protocol.cloud.verification_url is None and not self.protocol.cloud.logged_in:
return await self.async_step_mi()

Expand All @@ -406,7 +412,9 @@ async def async_step_2fa(self, user_input: dict[str, Any] | None = None, errors:
errors=errors,
)

async def async_step_captcha(self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = {}):
async def async_step_captcha(self, user_input: dict[str, Any] | None = None, errors: dict[str, Any] | None = None):
if errors is None:
errors = {}
if self.protocol.cloud.captcha_img is None and not self.protocol.cloud.logged_in:
return await self.async_step_mi()

Expand Down Expand Up @@ -438,10 +446,12 @@ async def async_step_captcha(self, user_input: dict[str, Any] | None = None, err
async def async_step_dreame(
self,
user_input: dict[str, Any] | None = None,
errors: dict[str, Any] | None = {},
errors: dict[str, Any] | None = None,
error: str | None = None,
) -> FlowResult:
"""Configure a dreame vacuum device through the Dreame Cloud."""
if errors is None:
errors = {}

description_placeholders = {}
if user_input is not None:
Expand Down Expand Up @@ -494,7 +504,7 @@ async def async_step_dreame(
async def async_step_mova(
self,
user_input: dict[str, Any] | None = None,
errors: dict[str, Any] | None = {},
errors: dict[str, Any] | None = None,
error: str | None = None,
) -> FlowResult:
"""Configure a dreame vacuum device through the Mova Cloud."""
Expand All @@ -504,7 +514,7 @@ async def async_step_mova(
async def async_step_trouver(
self,
user_input: dict[str, Any] | None = None,
errors: dict[str, Any] | None = {},
errors: dict[str, Any] | None = None,
error: str | None = None,
) -> FlowResult:
"""Configure a dreame vacuum device through the Trouver Cloud."""
Expand Down
6 changes: 3 additions & 3 deletions custom_components/dreame_vacuum/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,19 @@ def _notification_dismiss_listener(self, type, data) -> None:
notifications = self.hass.data.get(persistent_notification.DOMAIN)
if self._has_warning:
if f"{DOMAIN}_{self._device.mac}_{NOTIFICATION_ID_WARNING}" not in notifications:
if NOTIFICATION_ID_WARNING in self._notify:
if self._notify is True or (isinstance(self._notify, list) and NOTIFICATION_ID_WARNING in self._notify):
self._device.clear_warning()
self._has_warning = self._device.status.has_warning

if self._low_water:
if f"{DOMAIN}_{self._device.mac}_{NOTIFICATION_ID_LOW_WATER}" not in notifications:
if NOTIFICATION_ID_WARNING in self._notify:
if self._notify is True or (isinstance(self._notify, list) and NOTIFICATION_ID_WARNING in self._notify):
self._device.clear_warning()
self._low_water = self._device.status.low_water

if self._drainage_status:
if f"{DOMAIN}_{self._device.mac}_{NOTIFICATION_ID_DRAINAGE_STATUS}" not in notifications:
if NOTIFICATION_ID_WARNING in self._notify:
if self._notify is True or (isinstance(self._notify, list) and NOTIFICATION_ID_WARNING in self._notify):
self._device.clear_warning()
self._drainage_status = self._device.status.draining_complete

Expand Down
18 changes: 6 additions & 12 deletions custom_components/dreame_vacuum/dreame/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,12 +1602,9 @@ def _dnd_task_changed(self, previous_dnd_task: Any = None) -> None:
]
if dnd_list and len(dnd_list) > 1:
dnd_list.sort(
key=cmp_to_key(
lambda a, b: (
b.id - a.id
if a.start == b.start
else int(a.start.replace(":", "")) - int(b.start.replace(":", ""))
)
key=lambda x: (
int(x.start.replace(":", "")) if x.start else 0,
-x.id if x.id is not None else 0,
)
)
self.status.dnd_tasks = dnd_list
Expand Down Expand Up @@ -1639,12 +1636,9 @@ def _schedule_changed(self, previous_schedule: Any = None) -> None:

if schedule_list and len(schedule_list) > 1:
schedule_list.sort(
key=cmp_to_key(
lambda a, b: (
b.id - a.id
if a.time == b.time
else int(a.time.replace(":", "")) - int(b.time.replace(":", ""))
)
key=lambda x: (
int(x.time.replace(":", "")) if x.time else 0,
-x.id if x.id is not None else 0,
)
)

Expand Down
30 changes: 12 additions & 18 deletions custom_components/dreame_vacuum/dreame/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,13 +1796,11 @@ def request_recovery_map_list(self) -> None:
)
if len(recovery_map_list) > 2:
recovery_map_list.sort(
key=cmp_to_key(
lambda a, b: (
int(a.map_type) - int(b.map_type)
if a.map_type is RecoveryMapType.EDITED
and b.map_type is RecoveryMapType.BACKUP
else 1 if a.date > b.date else -1
)
key=lambda x: (
0 if x.map_type is RecoveryMapType.EDITED
else 2 if x.map_type is RecoveryMapType.BACKUP
else 1,
x.date
)
)

Expand Down Expand Up @@ -6523,10 +6521,10 @@ def set_segment_color_index(map_data: MapData, segment_info, walls_info=None) ->
max_area_item = max(segment_info, key=lambda s: s[2])
sorted_segments = [max_area_item] + sorted(
[s for s in segment_info if s[0] != max_area_item[0]],
key=cmp_to_key(DreameVacuumMapDecoder._compare_segment_neighbors),
key=lambda s: (-len(s[1]) if s[1] else 0, s[0]),
)
else:
sorted_segments = sorted(segment_info, key=cmp_to_key(DreameVacuumMapDecoder._compare_segment_neighbors))
sorted_segments = sorted(segment_info, key=lambda s: (-len(s[1]) if s[1] else 0, s[0]))

for segment in sorted_segments:
used_ids = []
Expand All @@ -6544,7 +6542,7 @@ def set_segment_color_index(map_data: MapData, segment_info, walls_info=None) ->

area_color_num = sorted(
area_color_num.values(),
key=cmp_to_key(DreameVacuumMapDecoder._compare_colors),
key=lambda x: (x[1], x[0]),
)

for area_color in area_color_num:
Expand Down Expand Up @@ -7137,7 +7135,7 @@ def render_map(self, map_data: MapData, robot_status: int = 0, station_status: i
val
for sublist in sorted(
floor_pixels,
key=cmp_to_key(DreameVacuumMapDataJsonRenderer._coordinate_tuple_sort),
key=lambda c: (c[1], c[0]),
)
for val in sublist
],
Expand All @@ -7152,7 +7150,7 @@ def render_map(self, map_data: MapData, robot_status: int = 0, station_status: i
val
for sublist in sorted(
wall_pixels,
key=cmp_to_key(DreameVacuumMapDataJsonRenderer._coordinate_tuple_sort),
key=lambda c: (c[1], c[0]),
)
for val in sublist
],
Expand All @@ -7173,7 +7171,7 @@ def render_map(self, map_data: MapData, robot_status: int = 0, station_status: i
val
for sublist in sorted(
v,
key=cmp_to_key(DreameVacuumMapDataJsonRenderer._coordinate_tuple_sort),
key=lambda c: (c[1], c[0]),
)
for val in sublist
],
Expand Down Expand Up @@ -12886,11 +12884,7 @@ def _check_intersect(self, arr1, arr2) -> list[int]:
if arr1[0] >= arr2[1] or arr2[0] >= arr1[1]:
return None

def sort_data(a, b):
return a - b

tmp = arr1 + arr2
tmp.sort(key=cmp_to_key(sort_data))
tmp = sorted(arr1 + arr2)
return [tmp[1], tmp[2]]

def _find_original_points(self, original_data, data, width, xs, ys) -> float:
Expand Down