Skip to content

Commit

Permalink
wrap dnd status inside an object
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Oct 7, 2017
1 parent eda0993 commit f461ed0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
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
25 changes: 24 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 @@ -325,6 +325,29 @@ def __repr__(self) -> str:
return "<ConsumableStatus main: %s, side: %s, filter: %s, sensor dirty: %s>" % ( # noqa: E501
self.main_brush, self.side_brush, self.filter, self.sensor_dirty)

class DNDStatus:
def __init__(self, data: Dict[str, Any]):
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:
Expand Down

0 comments on commit f461ed0

Please sign in to comment.