This repository has been archived by the owner on Mar 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor GetLifeSpan * refactor GetStats * refactor GetBattery * refactor GetChargeState * refactor Charge * refactor clean commands * refactor GetCleanLogs * refactor GetError * refactor PlaySound * refactor getCleanInfo * refactor setRelocationState * move map commands * improve enums * add CustomCommand * log on timeout * fix message handling * refactor handle method. Only pass command or command_name
- Loading branch information
Showing
30 changed files
with
973 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,74 @@ | ||
"""Commands module.""" | ||
from typing import Dict, List, Type | ||
|
||
from .base import Command, SetCommand | ||
from .base import Command, CommandWithHandling, SetCommand | ||
from .battery import GetBattery | ||
from .charge import Charge | ||
from .charge_state import GetChargeState | ||
from .clean import Clean, CleanArea, GetCleanInfo | ||
from .clean_logs import GetCleanLogs | ||
from .error import GetError | ||
from .fan_speed import FanSpeedLevel, GetFanSpeed, SetFanSpeed | ||
from .life_span import GetLifeSpan | ||
from .map import ( | ||
GetCachedMapInfo, | ||
GetMajorMap, | ||
GetMapSet, | ||
GetMapSubSet, | ||
GetMapTrace, | ||
GetMinorMap, | ||
GetPos, | ||
) | ||
from .play_sound import PlaySound | ||
from .relocation import SetRelocationState | ||
from .stats import GetStats | ||
from .water_info import GetWaterInfo, SetWaterInfo, WaterLevel | ||
|
||
# fmt: off | ||
_COMMANDS: List[Type[Command]] = [ | ||
GetWaterInfo, | ||
SetWaterInfo, | ||
# ordered by file asc | ||
_COMMANDS: List[Type[CommandWithHandling]] = [ | ||
GetBattery, | ||
|
||
Charge, | ||
|
||
GetChargeState, | ||
|
||
Clean, | ||
CleanArea, | ||
GetCleanInfo, | ||
|
||
GetCleanLogs, | ||
|
||
GetError, | ||
|
||
GetFanSpeed, | ||
SetFanSpeed | ||
SetFanSpeed, | ||
|
||
GetLifeSpan, | ||
|
||
PlaySound, | ||
|
||
SetRelocationState, | ||
|
||
GetStats, | ||
|
||
GetWaterInfo, | ||
SetWaterInfo, | ||
] | ||
# fmt: on | ||
|
||
COMMANDS: Dict[str, Type[Command]] = {cmd.name: cmd for cmd in _COMMANDS} # type: ignore | ||
COMMANDS: Dict[str, Type[CommandWithHandling]] = {cmd.name: cmd for cmd in _COMMANDS} | ||
|
||
SET_COMMAND_NAMES: List[str] = [ | ||
cmd.name for cmd in COMMANDS.values() if issubclass(cmd, SetCommand) | ||
] | ||
|
||
MAP_COMMANDS: List[Type[Command]] = [ | ||
GetMajorMap, | ||
GetMapSet, | ||
GetMinorMap, | ||
GetPos, | ||
GetMapTrace, | ||
GetMapSubSet, | ||
GetCachedMapInfo, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Battery commands.""" | ||
import logging | ||
from typing import Any, Dict | ||
|
||
from ..events import BatteryEvent | ||
from .base import VacuumEmitter, _NoArgsCommand | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class GetBattery(_NoArgsCommand): | ||
"""Get battery command.""" | ||
|
||
name = "getBattery" | ||
|
||
@classmethod | ||
def _handle_body_data_dict( | ||
cls, events: VacuumEmitter, data: Dict[str, Any] | ||
) -> bool: | ||
"""Handle message->body->data and notify the correct event subscribers. | ||
:return: True if data was valid and no error was included | ||
""" | ||
try: | ||
events.battery.notify(BatteryEvent(data["value"])) | ||
except ValueError: | ||
_LOGGER.warning("Couldn't parse battery status: %s", data) | ||
return True |
Oops, something went wrong.