diff --git a/eufy_robovac/property.py b/eufy_robovac/property.py index 26aff04..e13bd69 100644 --- a/eufy_robovac/property.py +++ b/eufy_robovac/property.py @@ -30,9 +30,9 @@ class DeviceProperty: self.type_cast = type_cast self.read_only = read_only - def __get__(self, instance): + def __get__(self, instance, owner): value = instance.state.get(self.key) - if value is not None and type_cast is not None: + if value is not None and self.type_cast is not None: value = self.type_cast(value) return value diff --git a/eufy_robovac/robovac.py b/eufy_robovac/robovac.py index 7a16306..59f0503 100644 --- a/eufy_robovac/robovac.py +++ b/eufy_robovac/robovac.py @@ -101,7 +101,7 @@ class Robovac(TuyaDevice): await self.async_set({self.GO_HOME: True}, callback) async def async_set_work_mode(self, work_mode, callback=None): - await self.async_set({self.WORK_MODE: work_mode}, callback) + await self.async_set({self.WORK_MODE: str(work_mode)}, callback) async def async_find_robot(self, callback=None): await self.async_set({self.FIND_ROBOT: True}, callback) diff --git a/eufy_robovac/tuya.py b/eufy_robovac/tuya.py index 327c4e2..af7db9f 100644 --- a/eufy_robovac/tuya.py +++ b/eufy_robovac/tuya.py @@ -413,14 +413,6 @@ def _call_async(fn, *args): loop.call_soon(wrapper, fn, *args) -def async_connection_needed(fn): - def wrapper(self, *args, **kwargs): - await self.async_connect() - return await fn(*args, **kwargs) - - return wrapper - - class TuyaDevice: """Represents a generic Tuya device.""" @@ -465,6 +457,8 @@ class TuyaDevice: return "{} ({}:{})".format(self.device_id, self.host, self.port) async def async_connect(self, callback=None): + if self._connected: + return sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) sock.settimeout(self.timeout) _LOGGER.debug("Connecting to {}".format(self)) @@ -555,8 +549,8 @@ class TuyaDevice: asyncio.ensure_future(self._async_handle_message()) - @async_connection_needed async def _async_send(self, message, retries=4): + await self.async_connect() _LOGGER.debug("Sending to {}: {}".format(self, message)) try: self.writer.write(message.bytes()) diff --git a/eufy_robovac/vacuum.py b/eufy_robovac/vacuum.py index a2f772f..9de082e 100644 --- a/eufy_robovac/vacuum.py +++ b/eufy_robovac/vacuum.py @@ -115,8 +115,6 @@ class EufyVacuum(VacuumDevice): """Return the status of the vacuum cleaner.""" if self.robovac.error_code != robovac.ErrorCode.NO_ERROR: return STATE_ERROR - elif self.robovac.work_status == robovac.WorkStatus.RECHARGE: - return STATE_ERROR elif self.robovac.go_home: return STATE_RETURNING elif self.robovac.work_status == robovac.WorkStatus.RUNNING: @@ -133,7 +131,7 @@ class EufyVacuum(VacuumDevice): @property def available(self) -> bool: """Return True if entity is available.""" - return self._available + return True async def async_return_to_base(self, **kwargs): """Set the vacuum cleaner to return to the dock.""" @@ -160,6 +158,10 @@ class EufyVacuum(VacuumDevice): """Turn the vacuum off and return to home.""" await self.async_return_to_base() + async def async_start(self, **kwargs): + """Resume the cleaning cycle.""" + await self.async_turn_on() + async def async_resume(self, **kwargs): """Resume the cleaning cycle.""" await self.robovac.async_play()