From 8dbe18a093505f171fdcae9962512f11d85386da Mon Sep 17 00:00:00 2001 From: magico13 Date: Mon, 5 Sep 2022 13:34:13 -0400 Subject: [PATCH] Update pyemvue version. Get outlets and chargers in one call. --- custom_components/emporia_vue/manifest.json | 2 +- custom_components/emporia_vue/switch.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/custom_components/emporia_vue/manifest.json b/custom_components/emporia_vue/manifest.json index fc34e2b..9d0824a 100644 --- a/custom_components/emporia_vue/manifest.json +++ b/custom_components/emporia_vue/manifest.json @@ -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": {}, diff --git a/custom_components/emporia_vue/switch.py b/custom_components/emporia_vue/switch.py index e79fcb4..7ba6158 100644 --- a/custom_components/emporia_vue/switch.py +++ b/custom_components/emporia_vue/switch.py @@ -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