From b5c5ab83dd7d0bdca62395eb5a14cd4fea951820 Mon Sep 17 00:00:00 2001 From: hultenvp <61835400+hultenvp@users.noreply.github.com> Date: Sun, 9 Jul 2023 12:27:28 +0200 Subject: [PATCH] Cleanup Ensure fixes do not break workarounds --- custom_components/solis/soliscloud_api.py | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/custom_components/solis/soliscloud_api.py b/custom_components/solis/soliscloud_api.py index 7e2add4..798f19f 100644 --- a/custom_components/solis/soliscloud_api.py +++ b/custom_components/solis/soliscloud_api.py @@ -130,7 +130,7 @@ INVERTER_LAT: ['latitude', float, 7], INVERTER_LON: ['longitude', float, 7], INVERTER_ADDRESS: ['cityStr', str, None], - #INVERTER_ENERGY_TODAY: ['dayEnergy', float, 2], #If override set + INVERTER_ENERGY_TODAY: ['dayEnergy', float, 2], #If override set GRID_DAILY_ENERGY_PURCHASED: ['gridPurchasedDayEnergy', float, 2], GRID_DAILY_ENERGY_PURCHASED_STR: ['gridPurchasedDayEnergyStr', str, None], GRID_MONTHLY_ENERGY_PURCHASED: ['gridPurchasedMonthEnergy', float, 2], @@ -283,16 +283,16 @@ async def fetch_inverter_data(self, inverter_serial: str) -> GinlongData | None: # Throttle http calls to avoid 502 error await asyncio.sleep(1) payload = await self._get_inverter_details(device_id, inverter_serial) - await asyncio.sleep(1) - payload2 = await self._get_station_from_list(self.config.plant_id) + #await asyncio.sleep(1) + #payload2 = await self._get_station_from_list(self.config.plant_id) await asyncio.sleep(1) payload_detail = await self._get_station_details(self.config.plant_id) if payload is not None: #_LOGGER.debug("%s", payload) self._collect_inverter_data(payload) self._post_process() - if payload2 is not None: - self._collect_station_data(payload2) + #if payload2 is not None: + # self._collect_station_list_data(payload2) if payload_detail is not None: self._collect_plant_data(payload_detail) self._post_process() @@ -399,10 +399,10 @@ async def _get_station_from_list(self, plant_id: str) -> dict[str, str] | None: _LOGGER.info('Unable to fetch details for Station with ID: %s', plant_id) return None - def _collect_station_data(self, payload: dict[str, Any]) -> None: + def _collect_station_list_data(self, payload: dict[str, Any]) -> None: """ Fetch dynamic properties """ jsondata = payload - attributes = INVERTER_DATA[PLANT_DETAIL] + attributes = INVERTER_DATA[PLANT_LIST] collect_energy_today = False try: collect_energy_today = \ @@ -427,13 +427,23 @@ def _collect_plant_data(self, payload: dict[str, Any]) -> None: """ Fetch dynamic properties """ jsondata = payload['data'] attributes = INVERTER_DATA[PLANT_DETAIL] + collect_energy_today = False + try: + collect_energy_today = \ + self.config.workarounds['use_energy_today_from_plant'] + except KeyError: + pass + if collect_energy_today: + _LOGGER.debug("Using stationDetail for energy_today") for dictkey in attributes: key = attributes[dictkey][0] type_ = attributes[dictkey][1] precision = attributes[dictkey][2] if key is not None: - value = self._get_value(jsondata, key, type_, precision) + value = None + if key != INVERTER_ENERGY_TODAY or collect_energy_today: + value = self._get_value(jsondata, key, type_, precision) if value is not None: self._data[dictkey] = value