async HTTP component (#3914)
* Migrate WSGI to asyncio * Rename wsgi -> http * Python 3.4 compat * Move linting to Python 3.4 * lint * Lint * Fix Python 3.4 mock_open + binary data * Surpress logging aiohttp.access * Spelling * Sending files is a coroutine * More callback annotations and naming fixes * Fix ios
This commit is contained in:
1 parent
9aa88819a5
commit
519d9f2fd0
45 files changed
+1422
-1009
No files matched your search
@@ -9,6 +9,7 @@ import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (CONF_EMAIL, CONF_NAME)
|
||||
@@ -57,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
email = config.get(CONF_EMAIL)
|
||||
sensors = {}
|
||||
|
||||
hass.wsgi.register_view(TorqueReceiveDataView(
|
||||
hass.http.register_view(TorqueReceiveDataView(
|
||||
hass, email, vehicle, sensors, add_devices))
|
||||
return True
|
||||
|
||||
@@ -77,9 +78,10 @@ class TorqueReceiveDataView(HomeAssistantView):
|
||||
self.sensors = sensors
|
||||
self.add_devices = add_devices
|
||||
|
||||
@callback
|
||||
def get(self, request):
|
||||
"""Handle Torque data request."""
|
||||
data = request.args
|
||||
data = request.GET
|
||||
|
||||
if self.email is not None and self.email != data[SENSOR_EMAIL_FIELD]:
|
||||
return
|
||||
@@ -100,14 +102,14 @@ class TorqueReceiveDataView(HomeAssistantView):
|
||||
elif is_value:
|
||||
pid = convert_pid(is_value.group(1))
|
||||
if pid in self.sensors:
|
||||
self.sensors[pid].on_update(data[key])
|
||||
self.sensors[pid].async_on_update(data[key])
|
||||
|
||||
for pid in names:
|
||||
if pid not in self.sensors:
|
||||
self.sensors[pid] = TorqueSensor(
|
||||
ENTITY_NAME_FORMAT.format(self.vehicle, names[pid]),
|
||||
units.get(pid, None))
|
||||
self.add_devices([self.sensors[pid]])
|
||||
self.hass.async_add_job(self.add_devices, [self.sensors[pid]])
|
||||
|
||||
return None
|
||||
|
||||
@@ -141,7 +143,8 @@ class TorqueSensor(Entity):
|
||||
"""Return the default icon of the sensor."""
|
||||
return 'mdi:car'
|
||||
|
||||
def on_update(self, value):
|
||||
@callback
|
||||
def async_on_update(self, value):
|
||||
"""Receive an update."""
|
||||
self._state = value
|
||||
self.update_ha_state()
|
||||
self.hass.loop.create_task(self.async_update_ha_state())
|
||||
Reference in new issue
Block a user