Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion miio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa
from miio.protocol import Message, Utils
from miio.vacuumcontainers import (VacuumStatus, ConsumableStatus,
from miio.vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus,
CleaningDetails, CleaningSummary, Timer)
from miio.vacuum import Vacuum, VacuumException
from miio.plug import Plug
Expand Down
4 changes: 2 additions & 2 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List
import enum

from .vacuumcontainers import (VacuumStatus, ConsumableStatus,
from .vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus,
CleaningSummary, CleaningDetails, Timer)
from .device import Device, DeviceException

Expand Down Expand Up @@ -165,7 +165,7 @@ def dnd_status(self):
"""Returns do-not-disturb status."""
# {'result': [{'enabled': 1, 'start_minute': 0, 'end_minute': 0,
# 'start_hour': 22, 'end_hour': 8}], 'id': 1}
return self.send("get_dnd_timer")
return DNDStatus(self.send("get_dnd_timer")[0])

def set_dnd(self, start_hr: int, start_min: int,
end_hr: int, end_min: int):
Expand Down
8 changes: 3 additions & 5 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,9 @@ def dnd(vac: miio.Vacuum, cmd: str,
end_hr, end_min))
click.echo(vac.set_dnd(start_hr, start_min, end_hr, end_min))
else:
x = vac.dnd_status()[0]
click.echo("DND %02i:%02i to %02i:%02i (enabled: %s)" % (
x['start_hour'], x['start_minute'],
x['end_hour'], x['end_minute'],
x['enabled']))
x = vac.dnd_status()
click.echo(click.style("Between %s and %s (enabled: %s)" % (
x.start, x.end, x.enabled), bold=x.enabled))


@cli.command()
Expand Down
29 changes: 28 additions & 1 deletion miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: UTF-8 -*#
from datetime import datetime, timedelta
from datetime import datetime, timedelta, time
from typing import Any, Dict, List
import warnings
import functools
Expand Down Expand Up @@ -326,6 +326,33 @@ def __repr__(self) -> str:
self.main_brush, self.side_brush, self.filter, self.sensor_dirty)


class DNDStatus:
def __init__(self, data: Dict[str, Any]):
# {'end_minute': 0, 'enabled': 1, 'start_minute': 0,
# 'start_hour': 22, 'end_hour': 8}
self.data = data

@property
def enabled(self) -> bool:
return bool(self.data["enabled"])

@property
def start(self) -> time:
return time(hour=self.data["start_hour"],
minute=self.data["start_minute"])

@property
def end(self) -> time:
return time(hour=self.data["end_hour"],
minute=self.data["end_minute"])

def __repr__(self):
return "<DNDStatus enabled: %s - between %s and %s>" % (
self.enabled,
self.start,
self.end)


class Timer:
def __init__(self, data: List[Any]) -> None:
# id / timestamp, enabled, ['<cron string>', ['command', 'params']
Expand Down