2024-11-30 15:06:00 +00:00
|
|
|
"""Implementation of vacuum."""
|
2024-06-02 15:30:02 +00:00
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from enum import IntEnum
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from ...feature import Feature
|
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..smartdevice import SmartDevice
|
|
|
|
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Status(IntEnum):
|
|
|
|
"""Status of vacuum."""
|
|
|
|
|
|
|
|
Idle = 0
|
|
|
|
Cleaning = 1
|
|
|
|
GoingHome = 4
|
|
|
|
Charging = 5
|
|
|
|
Charged = 6
|
|
|
|
Paused = 7
|
|
|
|
Error = 100
|
|
|
|
Unknown = 101
|
|
|
|
|
|
|
|
|
|
|
|
class Vacuum(SmartModule):
|
2024-11-30 15:06:00 +00:00
|
|
|
"""Implementation of vacuum support."""
|
2024-06-02 15:30:02 +00:00
|
|
|
|
|
|
|
REQUIRED_COMPONENT = "clean"
|
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
def __init__(self, device: SmartDevice, module: str) -> None:
|
2024-06-02 15:30:02 +00:00
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-11-30 15:17:20 +00:00
|
|
|
id="vacuum_return_home",
|
|
|
|
name="Return home",
|
2024-06-02 15:30:02 +00:00
|
|
|
container=self,
|
|
|
|
attribute_setter="return_home",
|
|
|
|
category=Feature.Category.Primary,
|
|
|
|
type=Feature.Action,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-11-30 15:17:20 +00:00
|
|
|
id="vacuum_start",
|
|
|
|
name="Start cleaning",
|
2024-06-02 15:30:02 +00:00
|
|
|
container=self,
|
|
|
|
attribute_setter="start",
|
|
|
|
category=Feature.Category.Primary,
|
|
|
|
type=Feature.Action,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-11-30 15:17:20 +00:00
|
|
|
id="vacuum_pause",
|
|
|
|
name="Pause",
|
2024-06-02 15:30:02 +00:00
|
|
|
container=self,
|
|
|
|
attribute_setter="pause",
|
|
|
|
category=Feature.Category.Primary,
|
|
|
|
type=Feature.Action,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-11-30 15:17:20 +00:00
|
|
|
id="vacuum_status",
|
|
|
|
name="Vacuum status",
|
2024-06-02 15:30:02 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="status",
|
|
|
|
category=Feature.Category.Primary,
|
|
|
|
type=Feature.Type.Sensor,
|
|
|
|
)
|
|
|
|
)
|
2024-11-30 16:26:56 +00:00
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
self._device,
|
|
|
|
"battery_level",
|
|
|
|
"Battery level",
|
|
|
|
container=self,
|
|
|
|
attribute_getter="battery",
|
|
|
|
icon="mdi:battery",
|
|
|
|
unit_getter=lambda: "%",
|
|
|
|
category=Feature.Category.Info,
|
|
|
|
type=Feature.Type.Sensor,
|
|
|
|
)
|
|
|
|
)
|
2024-06-02 15:30:02 +00:00
|
|
|
|
|
|
|
def query(self) -> dict:
|
|
|
|
"""Query to execute during the update cycle."""
|
2024-11-30 16:26:56 +00:00
|
|
|
return {"getVacStatus": None, "getBatteryInfo": None}
|
2024-06-02 15:30:02 +00:00
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def start(self) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Start cleaning."""
|
|
|
|
# If we are paused, do not restart cleaning
|
|
|
|
|
|
|
|
if self.status == Status.Paused:
|
|
|
|
return await self.resume()
|
|
|
|
|
|
|
|
# TODO: we need to create settings for clean_modes
|
2024-06-02 16:52:30 +00:00
|
|
|
return await self.call(
|
2024-06-02 15:30:02 +00:00
|
|
|
"setSwitchClean",
|
|
|
|
{
|
|
|
|
"clean_mode": 0,
|
|
|
|
"clean_on": True,
|
|
|
|
"clean_order": True,
|
|
|
|
"force_clean": False,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def pause(self) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Pause cleaning."""
|
|
|
|
return await self.set_pause(True)
|
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def resume(self) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Resume cleaning."""
|
|
|
|
return await self.set_pause(False)
|
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def set_pause(self, enabled: bool) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Pause or resume cleaning."""
|
2024-06-02 16:52:30 +00:00
|
|
|
return await self.call("setRobotPause", {"pause": enabled})
|
2024-06-02 15:30:02 +00:00
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def return_home(self) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Return home."""
|
|
|
|
return await self.set_return_home(True)
|
|
|
|
|
2024-11-30 15:06:00 +00:00
|
|
|
async def set_return_home(self, enabled: bool) -> dict:
|
2024-06-02 15:30:02 +00:00
|
|
|
"""Return home / pause returning."""
|
2024-06-02 16:52:30 +00:00
|
|
|
return await self.call("setSwitchCharge", {"switch_charge": enabled})
|
2024-06-02 15:30:02 +00:00
|
|
|
|
2024-11-30 16:26:56 +00:00
|
|
|
@property
|
|
|
|
def battery(self) -> int:
|
|
|
|
"""Return battery level."""
|
|
|
|
return self.data["getBatteryInfo"]["battery_percentage"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _vac_status(self) -> dict:
|
|
|
|
"""Return vac status container."""
|
|
|
|
return self.data["getVacStatus"]
|
|
|
|
|
2024-06-02 15:30:02 +00:00
|
|
|
@property
|
|
|
|
def status(self) -> Status:
|
|
|
|
"""Return current status."""
|
2024-11-30 16:26:56 +00:00
|
|
|
if self._vac_status.get("err_status"):
|
2024-06-02 15:30:02 +00:00
|
|
|
return Status.Error
|
2024-11-30 15:06:00 +00:00
|
|
|
|
2024-11-30 16:26:56 +00:00
|
|
|
status_code = self._vac_status["status"]
|
2024-06-02 15:30:02 +00:00
|
|
|
try:
|
|
|
|
return Status(status_code)
|
2024-11-30 15:06:00 +00:00
|
|
|
except ValueError:
|
2024-06-02 15:30:02 +00:00
|
|
|
_LOGGER.warning("Got unknown status code: %s (%s)", status_code, self.data)
|
|
|
|
return Status.Unknown
|