Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ omit =
homeassistant/components/weather/zamg.py
homeassistant/components/zeroconf.py
homeassistant/components/zwave/util.py
homeassistant/components/vacuum/mqtt.py


[report]
Expand Down
35 changes: 35 additions & 0 deletions homeassistant/components/vacuum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,41 @@
SUPPORT_MAP = 2048


SERVICE_TO_STRING = {
SUPPORT_TURN_ON: 'turn_on',
SUPPORT_TURN_OFF: 'turn_off',
SUPPORT_PAUSE: 'pause',
SUPPORT_STOP: 'stop',
SUPPORT_RETURN_HOME: 'return_home',
SUPPORT_FAN_SPEED: 'fan_speed',
SUPPORT_BATTERY: 'battery',
SUPPORT_STATUS: 'status',
SUPPORT_SEND_COMMAND: 'send_command',
SUPPORT_LOCATE: 'locate',
SUPPORT_CLEAN_SPOT: 'clean_spot',
SUPPORT_MAP: 'map',
}

STRING_TO_SERVICE = {v: k for k, v in SERVICE_TO_STRING.items()}


def services_to_strings(services):
"""Convert SUPPORT_* service bitmask to list of service strings."""
strings = []
for service in SERVICE_TO_STRING:
if service & services:
strings.append(SERVICE_TO_STRING[service])
return strings


def strings_to_services(strings):
"""Convert service strings to SUPPORT_* service bitmask."""
services = 0
for string in strings:
services |= STRING_TO_SERVICE[string]
return services


@bind_hass
def is_on(hass, entity_id=None):
"""Return if the vacuum is on based on the statemachine."""
Expand Down
57 changes: 34 additions & 23 deletions homeassistant/components/vacuum/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
"""
import asyncio
import logging

from homeassistant.components.vacuum import (
Expand Down Expand Up @@ -36,9 +37,10 @@
DEMO_VACUUM_NONE = '4_Fourth_floor'


def setup_platform(hass, config, add_devices, discovery_info=None):
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Demo vacuums."""
add_devices([
async_add_devices([
DemoVacuum(DEMO_VACUUM_COMPLETE, SUPPORT_ALL_SERVICES),
DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES),
DemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES),
Expand Down Expand Up @@ -121,7 +123,8 @@ def supported_features(self):
"""Flag supported features."""
return self._supported_features

def turn_on(self, **kwargs):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Turn the vacuum on."""
if self.supported_features & SUPPORT_TURN_ON == 0:
return
Expand All @@ -130,27 +133,30 @@ def turn_on(self, **kwargs):
self._cleaned_area += 5.32
self._battery_level -= 2
self._status = 'Cleaning'
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def turn_off(self, **kwargs):
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Turn the vacuum off."""
if self.supported_features & SUPPORT_TURN_OFF == 0:
return

self._state = False
self._status = 'Charging'
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def stop(self, **kwargs):
"""Turn the vacuum off."""
@asyncio.coroutine
def async_stop(self, **kwargs):
"""Stop the vacuum."""
if self.supported_features & SUPPORT_STOP == 0:
return

self._state = False
self._status = 'Stopping the current task'
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def clean_spot(self, **kwargs):
@asyncio.coroutine
def async_clean_spot(self, **kwargs):
"""Perform a spot clean-up."""
if self.supported_features & SUPPORT_CLEAN_SPOT == 0:
return
Expand All @@ -159,17 +165,19 @@ def clean_spot(self, **kwargs):
self._cleaned_area += 1.32
self._battery_level -= 1
self._status = "Cleaning spot"
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def locate(self, **kwargs):
"""Turn the vacuum off."""
@asyncio.coroutine
def async_locate(self, **kwargs):
"""Locate the vacuum (usually by playing a song)."""
if self.supported_features & SUPPORT_LOCATE == 0:
return

self._status = "Hi, I'm over here!"
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def start_pause(self, **kwargs):
@asyncio.coroutine
def async_start_pause(self, **kwargs):
"""Start, pause or resume the cleaning task."""
if self.supported_features & SUPPORT_PAUSE == 0:
return
Expand All @@ -181,32 +189,35 @@ def start_pause(self, **kwargs):
self._battery_level -= 1
else:
self._status = 'Pausing the current task'
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def set_fan_speed(self, fan_speed, **kwargs):
"""Tell the vacuum to return to its dock."""
@asyncio.coroutine
def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set the vacuum's fan speed."""
if self.supported_features & SUPPORT_FAN_SPEED == 0:
return

if fan_speed in self.fan_speed_list:
self._fan_speed = fan_speed
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def return_to_base(self, **kwargs):
@asyncio.coroutine
def async_return_to_base(self, **kwargs):
"""Tell the vacuum to return to its dock."""
if self.supported_features & SUPPORT_RETURN_HOME == 0:
return

self._state = False
self._status = 'Returning home...'
self._battery_level += 5
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

def send_command(self, command, params=None, **kwargs):
@asyncio.coroutine
def async_send_command(self, command, params=None, **kwargs):
"""Send a command to the vacuum."""
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
return

self._status = 'Executing {}({})'.format(command, params)
self._state = True
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()
Loading