From 3e78b0b9ba10a3c478d9b1f6f8e70b0faef919fb Mon Sep 17 00:00:00 2001 From: rikman122 Date: Sat, 12 Jun 2021 12:55:24 +0200 Subject: [PATCH] added Power control DP --- custom_components/localtuya/const.py | 1 + .../localtuya/translations/en.json | 6 +++-- custom_components/localtuya/vacuum.py | 25 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index ff21ff9..f844609 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -42,6 +42,7 @@ CONF_FAN_SPEED_HIGH = "fan_speed_high" CONF_SCALING = "scaling" # vacuum +CONF_POWERGO_DP = "powergo_dp" CONF_IDLE_STATUS_VALUE = "idle_status_value" CONF_RETURNING_STATUS_VALUE = "returning_status_value" CONF_DOCKED_STATUS_VALUE = "docked_status_value" diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 027d8be..d1f9b24 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -60,12 +60,13 @@ "scaling": "Scaling Factor", "state_on": "On Value", "state_off": "Off Value", + "powergo_dp": "Power DP (Usually 25 or 2)", "idle_status_value": "Idle Status (comma-separated)", "returning_status_value": "Returning Status", "docked_status_value": "Docked Status (comma-separated)", "battery_dp": "Battery status DP (Usually 14)", "mode_dp": "Mode DP (Usually 27)", - "modes": "Modes list [start,pause/stop,return home,others...]", + "modes": "Modes list in this order: return home,others...", "fan_speed_dp": "Fan speeds DP (Usually 30)", "fan_speeds": "Fan speeds list (comma-separated)", "clean_time_dp": "Clean Time DP (Usually 33)", @@ -122,12 +123,13 @@ "scaling": "Scaling Factor", "state_on": "On Value", "state_off": "Off Value", + "powergo_dp": "Power DP (Usually 25 or 2)", "idle_status_value": "Idle Status (comma-separated)", "returning_status_value": "Returning Status", "docked_status_value": "Docked Status (comma-separated)", "battery_dp": "Battery status DP (Usually 14)", "mode_dp": "Mode DP (Usually 27)", - "modes": "Modes list [start,pause/stop,return home,others...]", + "modes": "Modes list in this order: return home,others...", "fan_speed_dp": "Fan speeds DP (Usually 30)", "fan_speeds": "Fan speeds list (comma-separated)", "clean_time_dp": "Clean Time DP (Usually 33)", diff --git a/custom_components/localtuya/vacuum.py b/custom_components/localtuya/vacuum.py index 4a5c9b5..94021c0 100644 --- a/custom_components/localtuya/vacuum.py +++ b/custom_components/localtuya/vacuum.py @@ -23,6 +23,7 @@ from homeassistant.components.vacuum import ( from .common import LocalTuyaEntity, async_setup_entry from .const import ( + CONF_POWERGO_DP, CONF_IDLE_STATUS_VALUE, CONF_RETURNING_STATUS_VALUE, CONF_DOCKED_STATUS_VALUE, @@ -42,16 +43,17 @@ CLEAN_AREA = "clean_area" MODES_LIST = "cleaning_mode_list" MODE = "cleaning_mode" -DEFAULT_IDLE_STATUS = "standby,sleep" +DEFAULT_IDLE_STATUS = "standby,sleep,pause" DEFAULT_RETURNING_STATUS = "docking" DEFAULT_DOCKED_STATUS = "charging,chargecompleted" -DEFAULT_MODES = "smart,standby,chargego,wall_follow,spiral,single" +DEFAULT_MODES = "chargego,smart,standby,wall_follow,spiral,single" DEFAULT_FAN_SPEEDS = "low,normal,high" 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.Optional(CONF_RETURNING_STATUS_VALUE, default=DEFAULT_RETURNING_STATUS): str, vol.Optional(CONF_BATTERY_DP): vol.In(dps), @@ -82,10 +84,7 @@ class LocaltuyaVacuum(LocalTuyaEntity, StateVacuumEntity): if self.has_config(CONF_MODES): self._modes_list = self._config[CONF_MODES].split(",") self._attrs[MODES_LIST] = self._modes_list - if len(self._modes_list) >= 3: - self._start_mode = self._modes_list[0] - self._pause_mode = self._modes_list[1] - self._return_mode = self._modes_list[2] + self._return_mode = self._modes_list[0] self._docked_status_list = [] if self.has_config(CONF_DOCKED_STATUS_VALUE): @@ -146,25 +145,25 @@ class LocaltuyaVacuum(LocalTuyaEntity, StateVacuumEntity): async def async_start(self, **kwargs): """Turn the vacuum on and start cleaning.""" - await self._device.set_dp(self._start_mode, self._config[CONF_MODE_DP]) + await self._device.set_dp(True, self._config[CONF_POWERGO_DP]) async def async_pause(self, **kwargs): """Stop the vacuum cleaner, do not return to base.""" - if self._pause_mode: - await self._device.set_dp(self._pause_mode, self._config[CONF_MODE_DP]) - else: - _LOGGER.error("Missing command for pause in commands set.") + await self._device.set_dp(False, self._config[CONF_POWERGO_DP]) async def async_return_to_base(self, **kwargs): """Set the vacuum cleaner to return to the dock.""" if self._return_mode: await self._device.set_dp(self._return_mode, self._config[CONF_MODE_DP]) else: - _LOGGER.error("Missing command for pause in commands set.") + _LOGGER.error("Missing command for return home in commands set.") async def async_stop(self, **kwargs): """Turn the vacuum off stopping the cleaning and returning home.""" - self.async_pause() + if self._return_mode: + await self._device.set_dp(self._return_mode, self._config[CONF_MODE_DP]) + else: + _LOGGER.error("Missing command for return home in commands set.") async def async_clean_spot(self, **kwargs): """Perform a spot clean-up."""