Async syntax (#17033)

* async-syntax-mqtt_room

* async-syntax-alert

* Additional fixes
This commit is contained in:
cdce8p 2018-10-01 14:44:11 +02:00 committed by Paulus Schoutsen
parent f0fbdd6a26
commit b5e3d8c337
4 changed files with 33 additions and 47 deletions

View file

@ -4,7 +4,6 @@ Support for MQTT room presence detection.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.mqtt_room/
"""
import asyncio
import logging
import json
from datetime import timedelta
@ -52,9 +51,8 @@ MQTT_PAYLOAD = vol.Schema(vol.All(json.loads, vol.Schema({
}, extra=vol.ALLOW_EXTRA)))
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up MQTT room Sensor."""
async_add_entities([MQTTRoomSensor(
config.get(CONF_NAME),
@ -81,8 +79,7 @@ class MQTTRoomSensor(Entity):
self._distance = None
self._updated = None
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Subscribe to MQTT events."""
@callback
def update_state(device_id, room, distance):
@ -118,7 +115,7 @@ class MQTTRoomSensor(Entity):
or timediff.seconds >= self._timeout:
update_state(**device)
return mqtt.async_subscribe(
return await mqtt.async_subscribe(
self.hass, self._state_topic, message_received, 1)
@property