🚑 Fixes Toon doing I/O in coroutines (#21657)

This commit is contained in:
Franck Nijhof 2019-03-05 00:52:00 +01:00 committed by Paulus Schoutsen
parent 81c252f917
commit 31b88197eb
5 changed files with 18 additions and 18 deletions

View File

@ -1,6 +1,7 @@
"""Support for Toon van Eneco devices.""" """Support for Toon van Eneco devices."""
import logging import logging
from typing import Any, Dict from typing import Any, Dict
from functools import partial
import voluptuous as vol import voluptuous as vol
@ -48,10 +49,11 @@ async def async_setup_entry(hass: HomeAssistantType,
conf = hass.data.get(DATA_TOON_CONFIG) conf = hass.data.get(DATA_TOON_CONFIG)
toon = Toon(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD], toon = await hass.async_add_executor_job(partial(
Toon, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD],
conf[CONF_CLIENT_ID], conf[CONF_CLIENT_SECRET], conf[CONF_CLIENT_ID], conf[CONF_CLIENT_SECRET],
tenant_id=entry.data[CONF_TENANT], tenant_id=entry.data[CONF_TENANT],
display_common_name=entry.data[CONF_DISPLAY]) display_common_name=entry.data[CONF_DISPLAY]))
hass.data.setdefault(DATA_TOON_CLIENT, {})[entry.entry_id] = toon hass.data.setdefault(DATA_TOON_CLIENT, {})[entry.entry_id] = toon

View File

@ -102,7 +102,7 @@ class ToonBinarySensor(ToonEntity, BinarySensorDevice):
return value return value
async def async_update(self) -> None: def update(self) -> None:
"""Get the latest data from the binary sensor.""" """Get the latest data from the binary sensor."""
section = getattr(self.toon, self.section) section = getattr(self.toon, self.section)
self._state = getattr(section, self.measurement) self._state = getattr(section, self.measurement)

View File

@ -117,7 +117,7 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
"""Set new operation mode.""" """Set new operation mode."""
self.toon.thermostat_state = HA_TOON[operation_mode] self.toon.thermostat_state = HA_TOON[operation_mode]
async def async_update(self) -> None: def update(self) -> None:
"""Update local state.""" """Update local state."""
if self.toon.thermostat_state is None: if self.toon.thermostat_state is None:
self._state = None self._state = None

View File

@ -1,6 +1,7 @@
"""Config flow to configure the Toon component.""" """Config flow to configure the Toon component."""
from collections import OrderedDict from collections import OrderedDict
import logging import logging
from functools import partial
import voluptuous as vol import voluptuous as vol
@ -75,11 +76,10 @@ class ToonFlowHandler(config_entries.ConfigFlow):
app = self.hass.data.get(DATA_TOON_CONFIG, {}) app = self.hass.data.get(DATA_TOON_CONFIG, {})
try: try:
toon = Toon(user_input[CONF_USERNAME], toon = await self.hass.async_add_executor_job(partial(
user_input[CONF_PASSWORD], Toon, user_input[CONF_USERNAME], user_input[CONF_PASSWORD],
app[CONF_CLIENT_ID], app[CONF_CLIENT_ID], app[CONF_CLIENT_SECRET],
app[CONF_CLIENT_SECRET], tenant_id=user_input[CONF_TENANT]))
tenant_id=user_input[CONF_TENANT])
displays = toon.display_names displays = toon.display_names
@ -136,12 +136,10 @@ class ToonFlowHandler(config_entries.ConfigFlow):
app = self.hass.data.get(DATA_TOON_CONFIG, {}) app = self.hass.data.get(DATA_TOON_CONFIG, {})
try: try:
Toon(self.username, await self.hass.async_add_executor_job(partial(
self.password, Toon, self.username, self.password, app[CONF_CLIENT_ID],
app[CONF_CLIENT_ID], app[CONF_CLIENT_SECRET], tenant_id=self.tenant,
app[CONF_CLIENT_SECRET], display_common_name=user_input[CONF_DISPLAY]))
tenant_id=self.tenant,
display_common_name=user_input[CONF_DISPLAY])
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected error while authenticating") _LOGGER.exception("Unexpected error while authenticating")

View File

@ -134,7 +134,7 @@ class ToonSensor(ToonEntity):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return self._unit_of_measurement return self._unit_of_measurement
async def async_update(self) -> None: def update(self) -> None:
"""Get the latest data from the sensor.""" """Get the latest data from the sensor."""
section = getattr(self.toon, self.section) section = getattr(self.toon, self.section)
value = None value = None