mirror of
https://github.com/mitchellrj/eufy_robovac.git
synced 2025-11-25 20:52:41 +00:00
More fixes
This commit is contained in:
@@ -30,9 +30,9 @@ class DeviceProperty:
|
|||||||
self.type_cast = type_cast
|
self.type_cast = type_cast
|
||||||
self.read_only = read_only
|
self.read_only = read_only
|
||||||
|
|
||||||
def __get__(self, instance):
|
def __get__(self, instance, owner):
|
||||||
value = instance.state.get(self.key)
|
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)
|
value = self.type_cast(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class Robovac(TuyaDevice):
|
|||||||
await self.async_set({self.GO_HOME: True}, callback)
|
await self.async_set({self.GO_HOME: True}, callback)
|
||||||
|
|
||||||
async def async_set_work_mode(self, work_mode, callback=None):
|
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):
|
async def async_find_robot(self, callback=None):
|
||||||
await self.async_set({self.FIND_ROBOT: True}, callback)
|
await self.async_set({self.FIND_ROBOT: True}, callback)
|
||||||
|
|||||||
@@ -413,14 +413,6 @@ def _call_async(fn, *args):
|
|||||||
loop.call_soon(wrapper, 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:
|
class TuyaDevice:
|
||||||
"""Represents a generic Tuya device."""
|
"""Represents a generic Tuya device."""
|
||||||
|
|
||||||
@@ -465,6 +457,8 @@ class TuyaDevice:
|
|||||||
return "{} ({}:{})".format(self.device_id, self.host, self.port)
|
return "{} ({}:{})".format(self.device_id, self.host, self.port)
|
||||||
|
|
||||||
async def async_connect(self, callback=None):
|
async def async_connect(self, callback=None):
|
||||||
|
if self._connected:
|
||||||
|
return
|
||||||
sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
||||||
sock.settimeout(self.timeout)
|
sock.settimeout(self.timeout)
|
||||||
_LOGGER.debug("Connecting to {}".format(self))
|
_LOGGER.debug("Connecting to {}".format(self))
|
||||||
@@ -555,8 +549,8 @@ class TuyaDevice:
|
|||||||
|
|
||||||
asyncio.ensure_future(self._async_handle_message())
|
asyncio.ensure_future(self._async_handle_message())
|
||||||
|
|
||||||
@async_connection_needed
|
|
||||||
async def _async_send(self, message, retries=4):
|
async def _async_send(self, message, retries=4):
|
||||||
|
await self.async_connect()
|
||||||
_LOGGER.debug("Sending to {}: {}".format(self, message))
|
_LOGGER.debug("Sending to {}: {}".format(self, message))
|
||||||
try:
|
try:
|
||||||
self.writer.write(message.bytes())
|
self.writer.write(message.bytes())
|
||||||
|
|||||||
@@ -115,8 +115,6 @@ class EufyVacuum(VacuumDevice):
|
|||||||
"""Return the status of the vacuum cleaner."""
|
"""Return the status of the vacuum cleaner."""
|
||||||
if self.robovac.error_code != robovac.ErrorCode.NO_ERROR:
|
if self.robovac.error_code != robovac.ErrorCode.NO_ERROR:
|
||||||
return STATE_ERROR
|
return STATE_ERROR
|
||||||
elif self.robovac.work_status == robovac.WorkStatus.RECHARGE:
|
|
||||||
return STATE_ERROR
|
|
||||||
elif self.robovac.go_home:
|
elif self.robovac.go_home:
|
||||||
return STATE_RETURNING
|
return STATE_RETURNING
|
||||||
elif self.robovac.work_status == robovac.WorkStatus.RUNNING:
|
elif self.robovac.work_status == robovac.WorkStatus.RUNNING:
|
||||||
@@ -133,7 +131,7 @@ class EufyVacuum(VacuumDevice):
|
|||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._available
|
return True
|
||||||
|
|
||||||
async def async_return_to_base(self, **kwargs):
|
async def async_return_to_base(self, **kwargs):
|
||||||
"""Set the vacuum cleaner to return to the dock."""
|
"""Set the vacuum cleaner to return to the dock."""
|
||||||
@@ -160,6 +158,10 @@ class EufyVacuum(VacuumDevice):
|
|||||||
"""Turn the vacuum off and return to home."""
|
"""Turn the vacuum off and return to home."""
|
||||||
await self.async_return_to_base()
|
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):
|
async def async_resume(self, **kwargs):
|
||||||
"""Resume the cleaning cycle."""
|
"""Resume the cleaning cycle."""
|
||||||
await self.robovac.async_play()
|
await self.robovac.async_play()
|
||||||
|
|||||||
Reference in New Issue
Block a user