mirror of
https://github.com/magico13/ha-emporia-vue.git
synced 2026-01-09 20:37:59 -05:00
Move IO out of event loop #2
This commit is contained in:
@@ -58,7 +58,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
#_LOGGER.info(entry_data)
|
||||
vue = PyEmVue()
|
||||
try:
|
||||
result = vue.login(username=email, password=password)
|
||||
loop = asyncio.get_event_loop()
|
||||
result = await loop.run_in_executor(None, vue.login, email, password)
|
||||
if not result:
|
||||
raise Exception("Could not authenticate with Emporia API")
|
||||
except Exception:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Config flow for Emporia Vue integration."""
|
||||
import logging
|
||||
|
||||
import asyncio
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
@@ -30,7 +30,9 @@ class VueHub:
|
||||
|
||||
async def authenticate(self, username, password) -> bool:
|
||||
"""Test if we can authenticate with the host."""
|
||||
return self.vue.login(username=username, password=password)
|
||||
loop = asyncio.get_event_loop()
|
||||
result = await loop.run_in_executor(None, self.vue.login, username, password)
|
||||
return result
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
import asyncio
|
||||
import async_timeout
|
||||
|
||||
from homeassistant.const import DEVICE_CLASS_POWER, POWER_WATT, ENERGY_WATT_HOUR, ENERGY_KILO_WATT_HOUR
|
||||
@@ -49,7 +50,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
# Note: asyncio.TimeoutError and aiohttp.ClientError are already
|
||||
# handled by the data update coordinator.
|
||||
data = {}
|
||||
channels = vue.get_recent_usage(scale=Scale.MINUTE.value)
|
||||
loop = asyncio.get_event_loop()
|
||||
channels = await loop.run_in_executor(None, vue.get_recent_usage, Scale.MINUTE.value)
|
||||
if channels:
|
||||
for channel in channels:
|
||||
id = '{0}-{1}'.format(channel.device_gid, channel.channel_num)
|
||||
@@ -84,8 +86,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
await coordinator.async_refresh()
|
||||
|
||||
_LOGGER.warn(coordinator.data)
|
||||
|
||||
async_add_entities(
|
||||
CurrentVuePowerSensor(coordinator, id) for idx, id in enumerate(coordinator.data)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user