|
| 1 | +"""Mop Auto-Wash Frequency command module.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from types import MappingProxyType |
| 6 | +from typing import TYPE_CHECKING, Any |
| 7 | + |
| 8 | +from deebot_client.command import InitParam |
| 9 | +from deebot_client.events import MopAutoWashFrequency, MopAutoWashFrequencyEvent |
| 10 | +from deebot_client.message import HandlingResult |
| 11 | +from deebot_client.util import get_enum |
| 12 | + |
| 13 | +from .common import JsonGetCommand, JsonSetCommand |
| 14 | + |
| 15 | +if TYPE_CHECKING: |
| 16 | + from deebot_client.event_bus import EventBus |
| 17 | + |
| 18 | + |
| 19 | +class GetMopAutoWashFrequency(JsonGetCommand): |
| 20 | + """Get Mop Auto-Wash Frequency command.""" |
| 21 | + |
| 22 | + name = "getWashInfo" |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def _handle_body_data_dict( |
| 26 | + cls, event_bus: EventBus, data: dict[str, Any] |
| 27 | + ) -> HandlingResult: |
| 28 | + """Handle message->body->data and notify the correct event subscribers. |
| 29 | +
|
| 30 | + :return: A message response |
| 31 | + """ |
| 32 | + event_bus.notify( |
| 33 | + MopAutoWashFrequencyEvent(MopAutoWashFrequency(int(data["interval"]))) |
| 34 | + ) |
| 35 | + return HandlingResult.success() |
| 36 | + |
| 37 | + |
| 38 | +class SetMopAutoWashFrequency(JsonSetCommand): |
| 39 | + """Set Mop Auto-Wash Frequency command.""" |
| 40 | + |
| 41 | + name = "setWashInfo" |
| 42 | + get_command = GetMopAutoWashFrequency |
| 43 | + _mqtt_params = MappingProxyType({"interval": InitParam(MopAutoWashFrequency)}) |
| 44 | + |
| 45 | + def __init__(self, interval: MopAutoWashFrequency | str) -> None: |
| 46 | + if isinstance(interval, str): |
| 47 | + interval = get_enum(MopAutoWashFrequency, interval) |
| 48 | + super().__init__({"interval": interval.value}) |
0 commit comments