-
Notifications
You must be signed in to change notification settings - Fork 0
/
vacuum.py
88 lines (68 loc) · 2.67 KB
/
vacuum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Support for Neato Connected Vacuums.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/vacuum.neato/
"""
import logging
from datetime import timedelta
from homeassistant.components.vacuum import (
StateVacuumDevice, SUPPORT_BATTERY, SUPPORT_PAUSE, SUPPORT_RETURN_HOME,
SUPPORT_STATE, SUPPORT_STOP, SUPPORT_START, STATE_IDLE,
STATE_PAUSED, STATE_CLEANING, STATE_DOCKED, STATE_RETURNING, STATE_ERROR,
SUPPORT_MAP, ATTR_STATUS, ATTR_BATTERY_LEVEL, ATTR_BATTERY_ICON,
SUPPORT_LOCATE)
from custom_components.gardena import (GARDENA_MOWERS, GARDENA_LOGIN)
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['gardena']
SCAN_INTERVAL = timedelta(minutes=5)
SUPPORT_GARDENA = SUPPORT_BATTERY | SUPPORT_RETURN_HOME | \
SUPPORT_STOP | SUPPORT_START | \
SUPPORT_STATE
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Neato vacuum."""
dev = []
for mower in hass.data[GARDENA_MOWERS]:
dev.append(GardenaSmartMower(hass, mower))
_LOGGER.debug("Adding mower as vacuums %s", dev)
add_entities(dev, True)
class GardenaSmartMower(StateVacuumDevice):
"""Representation of a Neato Connected Vacuum."""
def __init__(self, hass, robot):
"""Initialize the Neato Connected Vacuum."""
self.robot = robot # type:
self.gardena = hass.data[GARDENA_LOGIN]
self._name = '{}'.format(self.robot.name)
def update(self):
"""Update the states of Gardena devices."""
_LOGGER.debug("Running Gardena update")
self.gardena.update_devices() # is a throttled update
@property
def name(self):
"""Return the name of the device."""
return self._name
@property
def supported_features(self):
"""Flag lawn mower robot features that are supported."""
return SUPPORT_GARDENA
@property
def battery_level(self):
"""Return the battery level of the lawn mower."""
return self.robot.get_battery_level()
@property
def state(self):
"""Return the status of the lawn mower."""
return self.robot.get_status()
@property
def device_state_attributes(self):
"""Return the state attributes of the lawn mower."""
return self.robot.get_info()
def start(self):
"""Start cleaning or resume cleaning."""
self.robot.start()
def return_to_base(self, **kwargs):
"""Set the lawn mower to return to the dock."""
# self._clean_state = STATE_RETURNING
self.robot.park_until_timer()
def stop(self, **kwargs):
"""Stop the lawn mower."""
self.robot.park()