Async syntax 3/8 (#17017)
* Async syntax 3, device_tracker & fan & hassio & image_processing & input * Pylint fixes
This commit is contained in:
parent
134eeecd65
commit
b24f9f5dfa
23 changed files with 194 additions and 286 deletions
|
@ -4,7 +4,6 @@ Support for the Geofency platform.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.geofency/
|
||||
"""
|
||||
import asyncio
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
|
@ -58,10 +57,9 @@ class GeofencyView(HomeAssistantView):
|
|||
self.see = see
|
||||
self.mobile_beacons = [slugify(beacon) for beacon in mobile_beacons]
|
||||
|
||||
@asyncio.coroutine
|
||||
def post(self, request):
|
||||
async def post(self, request):
|
||||
"""Handle Geofency requests."""
|
||||
data = yield from request.post()
|
||||
data = await request.post()
|
||||
hass = request.app['hass']
|
||||
|
||||
data = self._validate_data(data)
|
||||
|
@ -69,7 +67,7 @@ class GeofencyView(HomeAssistantView):
|
|||
return ("Invalid data", HTTP_UNPROCESSABLE_ENTITY)
|
||||
|
||||
if self._is_mobile_beacon(data):
|
||||
return (yield from self._set_location(hass, data, None))
|
||||
return await self._set_location(hass, data, None)
|
||||
if data['entry'] == LOCATION_ENTRY:
|
||||
location_name = data['name']
|
||||
else:
|
||||
|
@ -78,7 +76,7 @@ class GeofencyView(HomeAssistantView):
|
|||
data[ATTR_LATITUDE] = data[ATTR_CURRENT_LATITUDE]
|
||||
data[ATTR_LONGITUDE] = data[ATTR_CURRENT_LONGITUDE]
|
||||
|
||||
return (yield from self._set_location(hass, data, location_name))
|
||||
return await self._set_location(hass, data, location_name)
|
||||
|
||||
@staticmethod
|
||||
def _validate_data(data):
|
||||
|
@ -121,12 +119,11 @@ class GeofencyView(HomeAssistantView):
|
|||
return "{}_{}".format(BEACON_DEV_PREFIX, data['name'])
|
||||
return data['device']
|
||||
|
||||
@asyncio.coroutine
|
||||
def _set_location(self, hass, data, location_name):
|
||||
async def _set_location(self, hass, data, location_name):
|
||||
"""Fire HA event to set location."""
|
||||
device = self._device_name(data)
|
||||
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(self.see, dev_id=device,
|
||||
gps=(data[ATTR_LATITUDE], data[ATTR_LONGITUDE]),
|
||||
location_name=location_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue