Update pyemvue version. Get outlets and chargers in one call.

This commit is contained in:
magico13
2022-09-05 13:34:13 -04:00
parent 677cceea4e
commit 8dbe18a093
2 changed files with 10 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
"name": "Emporia Vue",
"config_flow": true,
"documentation": "https://github.com/magico13/ha-emporia-vue",
"requirements": ["pyemvue==0.15.1"],
"requirements": ["pyemvue==0.16.1"],
"ssdp": [],
"zeroconf": [],
"homekit": {},

View File

@@ -16,12 +16,14 @@ from homeassistant.helpers.update_coordinator import (
UpdateFailed,
)
from pyemvue.device import ChargerDevice, OutletDevice, VueDevice
from .charger_entity import EmporiaChargerEntity
from .const import DOMAIN, VUE_DATA
_LOGGER = logging.getLogger(__name__)
device_information = {} # data is the populated device objects
device_information: dict[int, VueDevice] = {} # data is the populated device objects
async def async_setup_entry(
@@ -33,7 +35,7 @@ async def async_setup_entry(
vue = hass.data[DOMAIN][config_entry.entry_id][VUE_DATA]
loop = asyncio.get_event_loop()
devices = await loop.run_in_executor(None, vue.get_devices)
devices: list[VueDevice] = await loop.run_in_executor(None, vue.get_devices)
for device in devices:
if device.outlet is not None:
await loop.run_in_executor(None, vue.populate_device_properties, device)
@@ -53,12 +55,14 @@ async def async_setup_entry(
# handled by the data update coordinator.
data = {}
loop = asyncio.get_event_loop()
# TODO: Swap from separate get_outlets/get_chargers to a single get_status
outlets = await loop.run_in_executor(None, vue.get_outlets)
outlets: list[OutletDevice]
chargers: list[ChargerDevice]
(outlets, chargers) = await loop.run_in_executor(
None, vue.get_devices_status
)
if outlets:
for outlet in outlets:
data[outlet.device_gid] = outlet
chargers = await loop.run_in_executor(None, vue.get_chargers)
if chargers:
for charger in chargers:
data[charger.device_gid] = charger