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
17 changes: 6 additions & 11 deletions homeassistant/components/cover/lutron_caseta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.lutron_caseta/
"""
import asyncio
import logging

from homeassistant.components.cover import (
Expand All @@ -18,8 +17,8 @@
DEPENDENCIES = ['lutron_caseta']


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the Lutron Caseta shades as a cover device."""
devs = []
bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE]
Expand Down Expand Up @@ -49,25 +48,21 @@ def current_cover_position(self):
"""Return the current position of cover."""
return self._state['current_state']

@asyncio.coroutine
def async_close_cover(self, **kwargs):
async def async_close_cover(self, **kwargs):
"""Close the cover."""
self._smartbridge.set_value(self._device_id, 0)

@asyncio.coroutine
def async_open_cover(self, **kwargs):
async def async_open_cover(self, **kwargs):
"""Open the cover."""
self._smartbridge.set_value(self._device_id, 100)

@asyncio.coroutine
def async_set_cover_position(self, **kwargs):
async def async_set_cover_position(self, **kwargs):
"""Move the shade to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
self._smartbridge.set_value(self._device_id, position)

@asyncio.coroutine
def async_update(self):
async def async_update(self):
"""Call when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id)
_LOGGER.debug(self._state)
35 changes: 13 additions & 22 deletions homeassistant/components/cover/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.mqtt/
"""
import asyncio
import logging

import voluptuous as vol
Expand Down Expand Up @@ -93,8 +92,8 @@
}).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema)


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the MQTT Cover."""
if discovery_info is not None:
config = PLATFORM_SCHEMA(discovery_info)
Expand Down Expand Up @@ -174,10 +173,9 @@ def __init__(self, name, state_topic, command_topic, availability_topic,
self._position_topic = position_topic
self._set_position_template = set_position_template

@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Subscribe MQTT events."""
yield from super().async_added_to_hass()
await super().async_added_to_hass()

@callback
def tilt_updated(topic, payload, qos):
Expand Down Expand Up @@ -218,7 +216,7 @@ def state_message_received(topic, payload, qos):
# Force into optimistic mode.
self._optimistic = True
else:
yield from mqtt.async_subscribe(
await mqtt.async_subscribe(
self.hass, self._state_topic,
state_message_received, self._qos)

Expand All @@ -227,7 +225,7 @@ def state_message_received(topic, payload, qos):
else:
self._tilt_optimistic = False
self._tilt_value = STATE_UNKNOWN
yield from mqtt.async_subscribe(
await mqtt.async_subscribe(
self.hass, self._tilt_status_topic, tilt_updated, self._qos)

@property
Expand Down Expand Up @@ -278,8 +276,7 @@ def supported_features(self):

return supported_features

@asyncio.coroutine
def async_open_cover(self, **kwargs):
async def async_open_cover(self, **kwargs):
"""Move the cover up.

This method is a coroutine.
Expand All @@ -292,8 +289,7 @@ def async_open_cover(self, **kwargs):
self._state = False
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_close_cover(self, **kwargs):
async def async_close_cover(self, **kwargs):
"""Move the cover down.

This method is a coroutine.
Expand All @@ -306,8 +302,7 @@ def async_close_cover(self, **kwargs):
self._state = True
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_stop_cover(self, **kwargs):
async def async_stop_cover(self, **kwargs):
"""Stop the device.

This method is a coroutine.
Expand All @@ -316,8 +311,7 @@ def async_stop_cover(self, **kwargs):
self.hass, self._command_topic, self._payload_stop, self._qos,
self._retain)

@asyncio.coroutine
def async_open_cover_tilt(self, **kwargs):
async def async_open_cover_tilt(self, **kwargs):
"""Tilt the cover open."""
mqtt.async_publish(self.hass, self._tilt_command_topic,
self._tilt_open_position, self._qos,
Expand All @@ -326,8 +320,7 @@ def async_open_cover_tilt(self, **kwargs):
self._tilt_value = self._tilt_open_position
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_close_cover_tilt(self, **kwargs):
async def async_close_cover_tilt(self, **kwargs):
"""Tilt the cover closed."""
mqtt.async_publish(self.hass, self._tilt_command_topic,
self._tilt_closed_position, self._qos,
Expand All @@ -336,8 +329,7 @@ def async_close_cover_tilt(self, **kwargs):
self._tilt_value = self._tilt_closed_position
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_set_cover_tilt_position(self, **kwargs):
async def async_set_cover_tilt_position(self, **kwargs):
"""Move the cover tilt to a specific position."""
if ATTR_TILT_POSITION not in kwargs:
return
Expand All @@ -350,8 +342,7 @@ def async_set_cover_tilt_position(self, **kwargs):
mqtt.async_publish(self.hass, self._tilt_command_topic,
level, self._qos, self._retain)

@asyncio.coroutine
def async_set_cover_position(self, **kwargs):
async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/cover/rflink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.rflink/
"""
import asyncio
import logging

import voluptuous as vol
Expand Down Expand Up @@ -79,8 +78,8 @@ def devices_from_config(domain_config, hass=None):
return devices


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the Rflink cover platform."""
async_add_devices(devices_from_config(config, hass))

Expand Down
50 changes: 20 additions & 30 deletions homeassistant/components/cover/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.template/
"""
import asyncio
import logging

import voluptuous as vol
Expand Down Expand Up @@ -72,8 +71,8 @@
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the Template cover."""
covers = []

Expand Down Expand Up @@ -199,8 +198,7 @@ def __init__(self, hass, device_id, friendly_name, state_template,
if self._entity_picture_template is not None:
self._entity_picture_template.hass = self.hass

@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def template_cover_state_listener(entity, old_state, new_state):
Expand Down Expand Up @@ -277,70 +275,62 @@ def should_poll(self):
"""Return the polling state."""
return False

@asyncio.coroutine
def async_open_cover(self, **kwargs):
async def async_open_cover(self, **kwargs):
"""Move the cover up."""
if self._open_script:
yield from self._open_script.async_run()
await self._open_script.async_run()
elif self._position_script:
yield from self._position_script.async_run({"position": 100})
await self._position_script.async_run({"position": 100})
if self._optimistic:
self._position = 100
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_close_cover(self, **kwargs):
async def async_close_cover(self, **kwargs):
"""Move the cover down."""
if self._close_script:
yield from self._close_script.async_run()
await self._close_script.async_run()
elif self._position_script:
yield from self._position_script.async_run({"position": 0})
await self._position_script.async_run({"position": 0})
if self._optimistic:
self._position = 0
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_stop_cover(self, **kwargs):
async def async_stop_cover(self, **kwargs):
"""Fire the stop action."""
if self._stop_script:
yield from self._stop_script.async_run()
await self._stop_script.async_run()

@asyncio.coroutine
def async_set_cover_position(self, **kwargs):
async def async_set_cover_position(self, **kwargs):
"""Set cover position."""
self._position = kwargs[ATTR_POSITION]
yield from self._position_script.async_run(
await self._position_script.async_run(
{"position": self._position})
if self._optimistic:
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_open_cover_tilt(self, **kwargs):
async def async_open_cover_tilt(self, **kwargs):
"""Tilt the cover open."""
self._tilt_value = 100
yield from self._tilt_script.async_run({"tilt": self._tilt_value})
await self._tilt_script.async_run({"tilt": self._tilt_value})
if self._tilt_optimistic:
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_close_cover_tilt(self, **kwargs):
async def async_close_cover_tilt(self, **kwargs):
"""Tilt the cover closed."""
self._tilt_value = 0
yield from self._tilt_script.async_run(
await self._tilt_script.async_run(
{"tilt": self._tilt_value})
if self._tilt_optimistic:
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_set_cover_tilt_position(self, **kwargs):
async def async_set_cover_tilt_position(self, **kwargs):
"""Move the cover tilt to a specific position."""
self._tilt_value = kwargs[ATTR_TILT_POSITION]
yield from self._tilt_script.async_run({"tilt": self._tilt_value})
await self._tilt_script.async_run({"tilt": self._tilt_value})
if self._tilt_optimistic:
self.async_schedule_update_ha_state()

@asyncio.coroutine
def async_update(self):
async def async_update(self):
"""Update the state from the template."""
if self._template is not None:
try:
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/cover/velbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
https://home-assistant.io/components/cover.velbus/
"""
import logging
import asyncio
import time

import voluptuous as vol
Expand Down Expand Up @@ -70,15 +69,14 @@ def __init__(self, velbus, name, module, open_channel, close_channel):
self._open_channel = open_channel
self._close_channel = close_channel

@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Add listener for Velbus messages on bus."""
def _init_velbus():
"""Initialize Velbus on startup."""
self._velbus.subscribe(self._on_message)
self.get_status()

yield from self.hass.async_add_job(_init_velbus)
await self.hass.async_add_job(_init_velbus)

def _on_message(self, message):
import velbus
Expand Down
5 changes: 1 addition & 4 deletions homeassistant/components/cover/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.wink/
"""
import asyncio

from homeassistant.components.cover import CoverDevice, STATE_UNKNOWN, \
ATTR_POSITION
from homeassistant.components.wink import WinkDevice, DOMAIN
Expand Down Expand Up @@ -34,8 +32,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WinkCoverDevice(WinkDevice, CoverDevice):
"""Representation of a Wink cover device."""

@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Call when entity is added to hass."""
self.hass.data[DOMAIN]['entities']['cover'].append(self)

Expand Down