Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Ensure fixes do not break workarounds
  • Loading branch information
hultenvp authored Jul 9, 2023
1 parent 585d292 commit b5c5ab8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions custom_components/solis/soliscloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = \
Expand All @@ -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

Expand Down

0 comments on commit b5c5ab8

Please sign in to comment.