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

Vacuum status #227

Merged
merged 2 commits into from
Jul 25, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.0.19

- Adjust vacuum state to HA v2025.1 standard and support docked, cleaning, returning (cleaning + pickup mode) and error
- Replace vacuum STOP service with PAUSE service
- Refactor service declaration to use HA services instead of local

## v1.0.18

- Change interval of calling API to once an hour (instead of a minute)
Expand Down
12 changes: 0 additions & 12 deletions custom_components/mydolphin_plus/common/calculated_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,3 @@ class CalculatedState(StrEnum):
INIT = "init"
HOLD_DELAY = "holddelay"
HOLD_WEEKLY = "holdweekly"

@staticmethod
def is_on_state(value) -> bool:
is_on = value in [
CalculatedState.INIT,
CalculatedState.CLEANING,
CalculatedState.PROGRAMMING,
CalculatedState.HOLD_WEEKLY,
CalculatedState.HOLD_DELAY,
]

return is_on
14 changes: 0 additions & 14 deletions custom_components/mydolphin_plus/common/clean_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ class CleanModes(StrEnum):
PICKUP = "pickup"


_ICON_CLEANING_MODES = {
CleanModes.REGULAR: "mdi:border-all-variant",
CleanModes.FAST_MODE: "mdi:clock-fast",
CleanModes.FLOOR_ONLY: "mdi:border-bottom-variant",
CleanModes.WATER_LINE: "mdi:format-align-top",
CleanModes.ULTRA_CLEAN: "mdi:border-all",
}

CLEAN_MODES_CYCLE_TIME = {
CleanModes.REGULAR: 120,
CleanModes.FAST_MODE: 60,
Expand All @@ -41,9 +33,3 @@ def get_clean_mode_cycle_time_key(clean_mode: CleanModes):
key = slugify(name)

return key


def get_clean_mode_icon(clean_mode: CleanModes):
icon = _ICON_CLEANING_MODES.get(clean_mode)

return icon
21 changes: 3 additions & 18 deletions custom_components/mydolphin_plus/common/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ATTR_EXPECTED_END_TIME = "expected_end_time"

ATTR_CALCULATED_STATUS = "Calculated State"
ATTR_VACUUM_STATE = "Vacuum State"
ATTR_POWER_SUPPLY_STATE = "Power Supply State"
ATTR_ROBOT_STATE = "Robot State"
ATTR_ROBOT_TYPE = "Robot Type"
Expand Down Expand Up @@ -130,8 +131,6 @@
ROBOT_DETAILS_URL = f"{BASE_API}/serialnumbers/getrobotdetailsbymusn/"
ROBOT_DETAILS_BY_SN_URL = f"{BASE_API}/serialnumbers/getrobotdetailsbyrobotsn/"

MAXIMUM_ATTEMPTS_GET_AWS_TOKEN = 5

API_REQUEST_HEADER_TOKEN = "token"
API_REQUEST_SERIAL_EMAIL = "Email"
API_REQUEST_SERIAL_PASSWORD = "Password"
Expand All @@ -142,8 +141,6 @@
API_RESPONSE_ALERT = "Alert"
API_RESPONSE_STATUS_FAILURE = "0"
API_RESPONSE_STATUS_SUCCESS = "1"
API_RESPONSE_STATUS_INVALID_REQUEST = "-1"
API_RESPONSE_STATUS_INVALID_MOTOR_UNIT_SERIAL = "-20"
API_RESPONSE_UNIT_SERIAL_NUMBER = "eSERNUM"

API_RESPONSE_IS_EMAIL_EXISTS = "isEmailExists"
Expand Down Expand Up @@ -171,7 +168,7 @@
LOGIN_HEADERS = {
"appkey": "346BDE92-53D1-4829-8A2E-B496014B586C",
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"integration-version": "1.0.18",
"integration-version": "1.0.19",
}

CA_FILE_NAME = "AmazonRootCA.pem"
Expand Down Expand Up @@ -282,7 +279,7 @@
| VacuumEntityFeature.RETURN_HOME
| VacuumEntityFeature.SEND_COMMAND
| VacuumEntityFeature.START
| VacuumEntityFeature.STOP
| VacuumEntityFeature.PAUSE
| VacuumEntityFeature.LOCATE
)

Expand All @@ -302,7 +299,6 @@
DATA_KEY_CYCLE_TIME = "Cycle Time"
DATA_KEY_CYCLE_TIME_LEFT = "Cycle Time Left"
DATA_KEY_AWS_BROKER = "AWS Broker"
DATA_KEY_SCHEDULE = "Schedule"
DATA_KEY_RSSI = "RSSI"
DATA_KEY_NETWORK_NAME = "Network Name"
DATA_KEY_CLEAN_MODE = "Clean Mode"
Expand All @@ -314,17 +310,6 @@
DATA_KEY_ROBOT_ERROR = "Robot Error"
DATA_KEY_PWS_ERROR = "Power Supply Error"

ACTION_ENTITY_RETURN_TO_BASE = "return_to_base"
ACTION_ENTITY_SET_FAN_SPEED = "set_fan_speed"
ACTION_ENTITY_START = "start"
ACTION_ENTITY_STOP = "stop"
ACTION_ENTITY_TURN_ON = "turn_on"
ACTION_ENTITY_TURN_OFF = "turn_off"
ACTION_ENTITY_SEND_COMMAND = "send_command"
ACTION_ENTITY_LOCATE = "locate"
ACTION_ENTITY_SELECT_OPTION = "select_option"
ACTION_ENTITY_SET_NATIVE_VALUE = "set_native_value"

TRANSLATION_KEY_ERROR_INSTRUCTIONS = "state_attributes.instructions.state"
ERROR_CLEAN_CODES = [0, 255]

Expand Down
14 changes: 4 additions & 10 deletions custom_components/mydolphin_plus/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

from homeassistant.components.light import ColorMode, LightEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect

from .common.base_entity import MyDolphinPlusBaseEntity, async_setup_entities
from .common.consts import (
ACTION_ENTITY_TURN_OFF,
ACTION_ENTITY_TURN_ON,
ATTR_ATTRIBUTES,
ATTR_IS_ON,
SIGNAL_DEVICE_NEW,
)
from .common.consts import ATTR_ATTRIBUTES, ATTR_IS_ON, SIGNAL_DEVICE_NEW
from .common.entity_descriptions import MyDolphinPlusLightEntityDescription
from .managers.coordinator import MyDolphinPlusCoordinator

Expand Down Expand Up @@ -57,10 +51,10 @@ def __init__(
self._attr_color_mode = ColorMode.ONOFF

async def async_turn_on(self, **kwargs: Any) -> None:
await self.async_execute_device_action(ACTION_ENTITY_TURN_ON)
await self.async_execute_device_action(SERVICE_TURN_ON)

async def async_turn_off(self, **kwargs: Any) -> None:
await self.async_execute_device_action(ACTION_ENTITY_TURN_OFF)
await self.async_execute_device_action(SERVICE_TURN_OFF)

def update_component(self, data):
"""Fetch new state parameters for the sensor."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mydolphin_plus/managers/aws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def _read_temperature_and_in_water_details(self):
def pickup(self):
self.set_cleaning_mode(CleanModes.PICKUP)

def power_off(self):
def pause(self):
request_data = {
DATA_SECTION_SYSTEM_STATE: {
DATA_SYSTEM_STATE_PWS_STATE: PowerSupplyState.OFF.value
Expand Down
72 changes: 40 additions & 32 deletions custom_components/mydolphin_plus/managers/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@

from voluptuous import MultipleInvalid

from homeassistant.const import ATTR_ICON, ATTR_MODE, ATTR_STATE, CONF_STATE
from homeassistant.components.number.const import SERVICE_SET_VALUE
from homeassistant.components.vacuum import (
SERVICE_LOCATE,
SERVICE_PAUSE,
SERVICE_RETURN_TO_BASE,
SERVICE_SEND_COMMAND,
SERVICE_SET_FAN_SPEED,
SERVICE_START,
)
from homeassistant.const import (
ATTR_ICON,
ATTR_MODE,
ATTR_STATE,
CONF_STATE,
SERVICE_SELECT_OPTION,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_IDLE,
)
from homeassistant.core import Event, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
Expand All @@ -17,16 +35,6 @@
from ..common.clean_modes import CleanModes, get_clean_mode_cycle_time_key
from ..common.connectivity_status import ConnectivityStatus
from ..common.consts import (
ACTION_ENTITY_LOCATE,
ACTION_ENTITY_RETURN_TO_BASE,
ACTION_ENTITY_SELECT_OPTION,
ACTION_ENTITY_SEND_COMMAND,
ACTION_ENTITY_SET_FAN_SPEED,
ACTION_ENTITY_SET_NATIVE_VALUE,
ACTION_ENTITY_START,
ACTION_ENTITY_STOP,
ACTION_ENTITY_TURN_OFF,
ACTION_ENTITY_TURN_ON,
API_RECONNECT_INTERVAL,
ATTR_ACTIONS,
ATTR_ATTRIBUTES,
Expand Down Expand Up @@ -492,18 +500,18 @@ def _get_vacuum_data(self, _entity_description) -> dict | None:
cleaning_mode = cycle_info.get(DATA_CYCLE_INFO_CLEANING_MODE, {})
mode = cleaning_mode.get(ATTR_MODE, CleanModes.REGULAR)

state = self._system_details.calculated_state.lower()
state = self._system_details.vacuum_state

result = {
ATTR_STATE: state,
ATTR_ATTRIBUTES: {ATTR_MODE: mode},
ATTR_ACTIONS: {
ACTION_ENTITY_START: self._vacuum_start,
ACTION_ENTITY_STOP: self._vacuum_stop,
ACTION_ENTITY_SET_FAN_SPEED: self._set_cleaning_mode,
ACTION_ENTITY_LOCATE: self._vacuum_locate,
ACTION_ENTITY_SEND_COMMAND: self._send_command,
ACTION_ENTITY_RETURN_TO_BASE: self._pickup,
SERVICE_START: self._vacuum_start,
SERVICE_PAUSE: self._vacuum_pause,
SERVICE_SET_FAN_SPEED: self._set_cleaning_mode,
SERVICE_LOCATE: self._vacuum_locate,
SERVICE_SEND_COMMAND: self._send_command,
SERVICE_RETURN_TO_BASE: self._pickup,
},
}

Expand All @@ -516,7 +524,7 @@ def _get_led_mode_data(self, _entity_description) -> dict | None:
result = {
ATTR_STATE: led_mode,
ATTR_ICON: ICON_LED_MODES.get(led_mode, LED_MODE_ICON_DEFAULT),
ATTR_ACTIONS: {ACTION_ENTITY_SELECT_OPTION: self._set_led_mode},
ATTR_ACTIONS: {SERVICE_SELECT_OPTION: self._set_led_mode},
}

return result
Expand All @@ -528,8 +536,8 @@ def _get_led_data(self, _entity_description) -> dict | None:
result = {
ATTR_IS_ON: led_enable,
ATTR_ACTIONS: {
ACTION_ENTITY_TURN_ON: self._set_led_enabled,
ACTION_ENTITY_TURN_OFF: self._set_led_disabled,
SERVICE_TURN_ON: self._set_led_enabled,
SERVICE_TURN_OFF: self._set_led_disabled,
},
}

Expand All @@ -542,7 +550,7 @@ def _get_led_intensity_data(self, _entity_description) -> dict | None:
result = {
ATTR_STATE: led_intensity,
ATTR_ACTIONS: {
ACTION_ENTITY_SET_NATIVE_VALUE: self._set_led_intensity,
SERVICE_SET_VALUE: self._set_led_intensity,
},
}

Expand All @@ -558,7 +566,7 @@ def _get_clean_mode_cycle_time_data(self, entity_description) -> dict | None:
result = {
ATTR_STATE: state,
ATTR_ACTIONS: {
ACTION_ENTITY_SET_NATIVE_VALUE: self._set_clean_mode_cycle_time_data,
SERVICE_SET_VALUE: self._set_clean_mode_cycle_time_data,
},
}

Expand Down Expand Up @@ -767,23 +775,25 @@ async def _set_clean_mode_cycle_time_data(
await self.config_manager.update_clean_cycle_time(clean_mode, cycle_time)

async def _pickup(self, _entity_description: EntityDescription):
_LOGGER.debug("Pickup robot")
_LOGGER.debug("Pickup vacuum")

self._aws_client.pickup()

async def _vacuum_start(self, _entity_description: EntityDescription, _state):
_LOGGER.debug("Start vacuum")

data = self._get_vacuum_data(None)
attributes = data.get(ATTR_ATTRIBUTES)
mode = attributes.get(ATTR_MODE, CleanModes.REGULAR)

self._aws_client.set_cleaning_mode(mode)

async def _vacuum_stop(self, _entity_description: EntityDescription, state):
is_on_state = CalculatedState.is_on_state(state)
_LOGGER.debug(f"Set vacuum power state, State: {state}, Power: {is_on_state}")
async def _vacuum_pause(self, _entity_description: EntityDescription, state):
is_idle_state = state == STATE_IDLE
_LOGGER.debug(f"Pause vacuum, State: {state}, State: {state}")

if is_on_state:
self._aws_client.power_off()
if is_idle_state:
self._aws_client.pause()

async def _vacuum_locate(self, entity_description: EntityDescription):
led_light_entity = self._get_led_data(None)
Expand Down Expand Up @@ -838,9 +848,7 @@ async def _service_navigate(self, data: dict[str, Any] | list[Any] | None):
self._aws_client.navigate(direction)

def _set_system_status_details(self):
data = self.aws_data

updated = self._system_details.update(data)
updated = self._system_details.update(self.aws_data)

if updated:
self._can_load_components = True
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mydolphin_plus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/sh00t2kill/dolphin-robot/issues",
"requirements": ["awsiotsdk"],
"version": "1.0.18"
"version": "1.0.19"
}
Loading
Loading