Skip to content

Commit

Permalink
Use python-miio as transport layer + various fixes with doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiğit Topcu committed Oct 30, 2022
1 parent c929e5b commit 7356402
Show file tree
Hide file tree
Showing 29 changed files with 482 additions and 679 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All features completely reverse engineered from the official Mi Home app RN plug
- [Customized room cleaning entities](https://github.com/Tasshack/dreame-vacuum/blob/master/docs/room_entities.md)
- [Services for device and map with examples](https://github.com/Tasshack/dreame-vacuum/blob/master/docs/services.md)
- [Persistent notifications and error reporting](https://github.com/Tasshack/dreame-vacuum/blob/master/docs/notifications.md)
- [Events for automations](https://github.com/Tasshack/dreame-vacuum/blob/master/docs/events.md)
- [Valetudo map card support](#with-valetudo-map-card)
- Onboard scheduling support *(Coming soon)*

Expand Down
8 changes: 4 additions & 4 deletions custom_components/dreame_vacuum/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
ConfigEntry,
ConfigFlow,
OptionsFlow,
SOURCE_REAUTH,
)

from .dreame import MiIODeviceProtocol, MiIOCloudProtocol, MAP_COLOR_SCHEME_LIST
from .dreame import DreameVacuumDeviceProtocol, DreameVacuumCloudProtocol, MAP_COLOR_SCHEME_LIST

from .const import (
DOMAIN,
Expand Down Expand Up @@ -198,7 +197,7 @@ async def async_step_connect(
errors: dict[str, str] = {}
if len(self.token) == 32:
try:
protocol = MiIODeviceProtocol(self.host, self.token)
protocol = DreameVacuumDeviceProtocol(self.host, self.token)
info = await self.hass.async_add_executor_job(protocol.connect, 2)
if info:
self.mac = info["mac"]
Expand Down Expand Up @@ -268,7 +267,7 @@ async def async_step_with_map(
self.password = password
self.country = country

protocol = MiIOCloudProtocol(
protocol = DreameVacuumCloudProtocol(
self.username, self.password, self.country)
await self.hass.async_add_executor_job(protocol.login)

Expand Down Expand Up @@ -367,6 +366,7 @@ async def async_step_options(
options={
CONF_NOTIFY: user_input[CONF_NOTIFY],
CONF_COLOR_SCHEME: user_input.get(CONF_COLOR_SCHEME),
CONF_MAP_OBJECTS: user_input.get(CONF_MAP_OBJECTS),
},
)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/dreame_vacuum/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
SERVICE_MERGE_SEGMENTS: Final = "vacuum_merge_segments"
SERVICE_SPLIT_SEGMENTS: Final = "vacuum_split_segments"
SERVICE_RENAME_SEGMENT: Final = "vacuum_rename_segment"
SERVICE_SET_CLEANING_ORDER: Final = "vacuum_set_cleaning_order"
SERVICE_SET_CLEANING_SEQUENCE: Final = "vacuum_set_cleaning_sequence"
SERVICE_SET_CUSTOM_CLEANING: Final = "vacuum_set_custom_cleaning"
SERVICE_SET_DND: Final = "vacuum_set_dnd"
SERVICE_INSTALL_VOICE_PACK: Final = "vacuum_install_voice_pack"
Expand Down Expand Up @@ -79,7 +79,7 @@
INPUT_URL: Final = "url"
INPUT_MD5: Final = "md5"
INPUT_SIZE: Final = "size"
INPUT_CLEANING_ORDER: Final = "cleaning_order"
INPUT_CLEANING_SEQUENCE: Final = "cleaning_sequence"
INPUT_DND_ENABLED: Final = "dnd_enabled"
INPUT_DND_START: Final = "dnd_start"
INPUT_DND_END: Final = "dnd_end"
Expand Down
10 changes: 5 additions & 5 deletions custom_components/dreame_vacuum/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
def _dust_collection_changed(self, previous_value=None) -> None:
if previous_value is not None:
if self.device.status.auto_emptying_not_performed:
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_DUST_COLLECTION_NOT_PERFORMED})
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_ID_DUST_COLLECTION})

self._create_persistent_notification(
NOTIFICATION_DUST_COLLECTION_NOT_PERFORMED,
Expand All @@ -134,9 +134,9 @@ def _cleaning_paused_changed(self, previous_value=None) -> None:
hour = math.floor(dnd_remaining / 3600)
minute = math.floor((dnd_remaining - hour * 3600) / 60)
notification = f"{NOTIFICATION_RESUME_CLEANING_NOT_PERFORMED}\n## Cleaning will start in {hour} hour(s) and {minute} minutes(s)"
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_RESUME_CLEANING_NOT_PERFORMED})
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_ID_CLEANING_PAUSED})
else:
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_RESUME_CLEANING})
self._fire_event(EVENT_INFORMATION, {EVENT_INFORMATION: NOTIFICATION_ID_CLEANING_PAUSED})

self._create_persistent_notification(
notification, NOTIFICATION_ID_CLEANING_PAUSED
Expand Down Expand Up @@ -193,7 +193,7 @@ def _task_status_changed(self, previous_value=None) -> None:
def _error_changed(self, previous_value=None) -> None:
has_warning = self.device.status.has_warning
if has_warning:
self._fire_event(EVENT_WARNING, {EVENT_WARNING: self.device.status.error_description[0]})
self._fire_event(EVENT_WARNING, {EVENT_WARNING: self.device.status.error_description[0], "code": self.device.status.error.value})

self._create_persistent_notification(
self.device.status.error_description[0], NOTIFICATION_ID_WARNING
Expand All @@ -204,7 +204,7 @@ def _error_changed(self, previous_value=None) -> None:

if self.device.status.has_error:
description = self.device.status.error_description
self._fire_event(EVENT_ERROR, {EVENT_ERROR: description[0]})
self._fire_event(EVENT_ERROR, {EVENT_ERROR: description[0], "code": self.device.status.error.value})

description = f"### {description[0]}\n{description[1]}"
image = self.device.status.error_image
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dreame_vacuum/dreame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
SUCTION_LEVEL_QUIET,
)
from .device import DreameVacuumDevice
from .protocol import MiIODeviceProtocol, MiIOCloudProtocol
from .protocol import DreameVacuumDeviceProtocol, DreameVacuumCloudProtocol
from .exceptions import DeviceException, DeviceUpdateFailedException, InvalidActionException, InvalidValueException
1 change: 0 additions & 1 deletion custom_components/dreame_vacuum/dreame/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
ATTR_MAPPING: Final = "mapping"
ATTR_ROOMS: Final = "rooms"
ATTR_CURRENT_SEGMENT: Final = "current_segment"
ATTR_MAP_ROOMS: Final = "map_rooms"
ATTR_SELECTED_MAP: Final = "selected_map"
ATTR_ID: Final = "id"
ATTR_NAME: Final = "name"
Expand Down
Loading

0 comments on commit 7356402

Please sign in to comment.