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

Update Vacuume to fumction with cheap tuya vacuum #4

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions custom_components/localtuya/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@

# vacuum
CONF_POWERGO_DP = "powergo_dp"
CONF_PAUSE_DP = "pause_dp"
CONF_PREFER_POWERGO = "use_powergo_to_start"
CONF_IDLE_STATUS_VALUE = "idle_status_value"
CONF_RETURNING_STATUS_VALUE = "returning_status_value"
CONF_DOCKED_STATUS_VALUE = "docked_status_value"
CONF_CLEANING_STATUS_VALUE = "cleaning_status_value"
CONF_BATTERY_DP = "battery_dp"
CONF_MODE_DP = "mode_dp"
CONF_MODES = "modes"
Expand Down
5 changes: 4 additions & 1 deletion custom_components/localtuya/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@
"state_on": "On Value",
"state_off": "Off Value",
"powergo_dp": "Power DP (Usually 25 or 2)",
"pause_dp": "Pause DP",
"use_powergo_to_start": "If no modes list use 'Power DP' instead of 'Pause DP' to start Cleaning",
"idle_status_value": "Idle Status (comma-separated)",
"returning_status_value": "Returning Status",
"docked_status_value": "Docked Status (comma-separated)",
"cleaning_status_value": "Cleaning Status (comma-separated)",
"fault_dp": "Fault DP (Usually 11)",
"battery_dp": "Battery status DP (Usually 14)",
"mode_dp": "Mode DP (Usually 27)",
"modes": "Modes list",
"modes": "Modes list (comma-separated, The first listed is used when starting)",
"return_mode": "Return home mode",
"fan_speed_dp": "Fan speeds DP (Usually 30)",
"fan_speeds": "Fan speeds list (comma-separated)",
Expand Down
77 changes: 51 additions & 26 deletions custom_components/localtuya/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@
STATE_IDLE,
STATE_PAUSED,
STATE_RETURNING,
SUPPORT_BATTERY,
SUPPORT_FAN_SPEED,
SUPPORT_LOCATE,
SUPPORT_PAUSE,
SUPPORT_RETURN_HOME,
SUPPORT_START,
SUPPORT_STATE,
SUPPORT_STATUS,
SUPPORT_STOP,
VacuumEntityFeature,
StateVacuumEntity,
)

Expand All @@ -30,6 +22,7 @@
CONF_CLEAN_RECORD_DP,
CONF_CLEAN_TIME_DP,
CONF_DOCKED_STATUS_VALUE,
CONF_CLEANING_STATUS_VALUE,
CONF_FAN_SPEED_DP,
CONF_FAN_SPEEDS,
CONF_FAULT_DP,
Expand All @@ -39,6 +32,8 @@
CONF_MODES,
CONF_PAUSED_STATE,
CONF_POWERGO_DP,
CONF_PAUSE_DP,
CONF_PREFER_POWERGO,
CONF_RETURN_MODE,
CONF_RETURNING_STATUS_VALUE,
CONF_STOP_STATUS,
Expand All @@ -57,6 +52,7 @@
DEFAULT_RETURNING_STATUS = "docking"
DEFAULT_DOCKED_STATUS = "charging,chargecompleted"
DEFAULT_MODES = "smart,wall_follow,spiral,single"
DEFAULT_CLEANING_STATUS = "smart_clean,zone_clean,part_clean,wallfollow,selectroom"
DEFAULT_FAN_SPEEDS = "low,normal,high"
DEFAULT_PAUSED_STATE = "paused"
DEFAULT_RETURN_MODE = "chargego"
Expand All @@ -67,8 +63,11 @@ def flow_schema(dps):
"""Return schema used in config flow."""
return {
vol.Required(CONF_IDLE_STATUS_VALUE, default=DEFAULT_IDLE_STATUS): str,
vol.Required(CONF_POWERGO_DP): vol.In(dps),
vol.Required(CONF_DOCKED_STATUS_VALUE, default=DEFAULT_DOCKED_STATUS): str,
vol.Required(CONF_CLEANING_STATUS_VALUE, default=DEFAULT_CLEANING_STATUS): str,
vol.Required(CONF_POWERGO_DP): vol.In(dps),
vol.Optional(CONF_PAUSE_DP): vol.In(dps),
vol.Optional(CONF_PREFER_POWERGO, default=False): bool,
vol.Optional(
CONF_RETURNING_STATUS_VALUE, default=DEFAULT_RETURNING_STATUS
): str,
Expand All @@ -84,10 +83,9 @@ def flow_schema(dps):
vol.Optional(CONF_LOCATE_DP): vol.In(dps),
vol.Optional(CONF_FAULT_DP): vol.In(dps),
vol.Optional(CONF_PAUSED_STATE, default=DEFAULT_PAUSED_STATE): str,
vol.Optional(CONF_STOP_STATUS, default=DEFAULT_STOP_STATUS): str,
vol.Optional(CONF_STOP_STATUS): str,
}


class LocaltuyaVacuum(LocalTuyaEntity, StateVacuumEntity):
"""Tuya vacuum device."""

Expand All @@ -111,6 +109,10 @@ def __init__(self, device, config_entry, switchid, **kwargs):
if self.has_config(CONF_DOCKED_STATUS_VALUE):
self._docked_status_list = self._config[CONF_DOCKED_STATUS_VALUE].split(",")

self._cleaning_status_list = []
if self.has_config(CONF_CLEANING_STATUS_VALUE):
self._cleaning_status_list = self._config[CONF_CLEANING_STATUS_VALUE].split(",")

self._fan_speed_list = []
if self.has_config(CONF_FAN_SPEEDS):
self._fan_speed_list = self._config[CONF_FAN_SPEEDS].split(",")
Expand All @@ -120,24 +122,33 @@ def __init__(self, device, config_entry, switchid, **kwargs):
_LOGGER.debug("Initialized vacuum [%s]", self.name)

@property
def supported_features(self):
def supported_features(self) -> VacuumEntityFeature:
"""Flag supported features."""
"""
unused:
TURN_ON -> Not going to use
TURN_OFF -> Not going to use
SEND_COMMAND -> Advaced commands can be sent to COMMAND_DP
CLEAN_SPOT -> Much work Ahead (need MAP)
MAP -> need to work out how to process map
"""
# Should be able to assume a Minimum feature set
supported_features = (
SUPPORT_START
| SUPPORT_PAUSE
| SUPPORT_STOP
| SUPPORT_STATUS
| SUPPORT_STATE
VacuumEntityFeature.START
| VacuumEntityFeature.PAUSE
| VacuumEntityFeature.STOP
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.STATE
)

if self.has_config(CONF_RETURN_MODE):
supported_features = supported_features | SUPPORT_RETURN_HOME
supported_features = supported_features | VacuumEntityFeature.RETURN_HOME
if self.has_config(CONF_FAN_SPEED_DP):
supported_features = supported_features | SUPPORT_FAN_SPEED
supported_features = supported_features | VacuumEntityFeature.FAN_SPEED
if self.has_config(CONF_BATTERY_DP):
supported_features = supported_features | SUPPORT_BATTERY
supported_features = supported_features | VacuumEntityFeature.BATTERY
if self.has_config(CONF_LOCATE_DP):
supported_features = supported_features | SUPPORT_LOCATE
supported_features = supported_features | VacuumEntityFeature.LOCATE

return supported_features

Expand Down Expand Up @@ -168,11 +179,22 @@ def fan_speed_list(self) -> list:

async def async_start(self, **kwargs):
"""Turn the vacuum on and start cleaning."""
await self._device.set_dp(True, self._config[CONF_POWERGO_DP])
if self._state in STATE_CLEANING:
return
if hasattr(self, "_modes_list") and self._state != STATE_PAUSED:
await self._device.set_dp(self._modes_list[0], self._config[CONF_MODE_DP])
elif self._state != STATE_PAUSED and self._config[CONF_PREFER_POWERGO]:
await self._device.set_dp(True, self._config[CONF_POWERGO_DP])
else:
await self.async_pause()

async def async_pause(self, **kwargs):
"""Stop the vacuum cleaner, do not return to base."""
await self._device.set_dp(False, self._config[CONF_POWERGO_DP])
if self.has_config(CONF_PAUSE_DP):
# toggling this because CONF_PAUSE_DP may be inverted
await self._device.set_dp(not self.dps_conf(CONF_PAUSE_DP) ,self._config[CONF_PAUSE_DP])
else:
await self._device.set_dp( True if self._state == STATE_PAUSED else False , self._config[CONF_POWERGO_DP])

async def async_return_to_base(self, **kwargs):
"""Set the vacuum cleaner to return to the dock."""
Expand All @@ -190,7 +212,8 @@ async def async_stop(self, **kwargs):
self._config[CONF_STOP_STATUS], self._config[CONF_MODE_DP]
)
else:
_LOGGER.error("Missing command for stop in commands set.")
await self._device.set_dp(False, self._config[CONF_POWERGO_DP])
# _LOGGER.error("Missing command for stop in commands set.")

async def async_clean_spot(self, **kwargs):
"""Perform a spot clean-up."""
Expand Down Expand Up @@ -219,12 +242,14 @@ def status_updated(self):
self._state = STATE_IDLE
elif state_value in self._docked_status_list:
self._state = STATE_DOCKED
elif state_value in self._cleaning_status_list:
self._state = STATE_CLEANING
elif state_value == self._config[CONF_RETURNING_STATUS_VALUE]:
self._state = STATE_RETURNING
elif state_value == self._config[CONF_PAUSED_STATE]:
self._state = STATE_PAUSED
else:
self._state = STATE_CLEANING
self._state = state_value

if self.has_config(CONF_BATTERY_DP):
self._battery_level = self.dps_conf(CONF_BATTERY_DP)
Expand Down
Loading