Skip to content

Commit

Permalink
Perform a single request to acquire device _and_ inverter data
Browse files Browse the repository at this point in the history
Complements klaasnicolaas/python-omnikinverter#340

Only a single request needs to be performed to retrieve all the
necessary data, which is stored in an object and later parsed into a
`Device` or `Inverter` `dataclass` when calling the respective function.
  • Loading branch information
MarijnS95 committed Aug 20, 2023
1 parent edc610f commit a26b744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions custom_components/omnik_inverter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def async_step_setup(
host=user_input[CONF_HOST],
source_type=self.source_type,
) as client:
await client.inverter()
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
Expand Down Expand Up @@ -183,7 +183,7 @@ async def async_step_setup_html(
username=user_input[CONF_USERNAME],
password=user_input[CONF_PASSWORD],
) as client:
await client.inverter()
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
Expand Down Expand Up @@ -237,7 +237,7 @@ async def async_step_setup_tcp(
source_type=self.source_type,
serial_number=user_input[CONF_SERIAL],
) as client:
await client.inverter()
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
Expand Down
5 changes: 3 additions & 2 deletions custom_components/omnik_inverter/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ async def _async_update_data(self) -> OmnikInverterData:
UpdateFailed: An error occurred when updating the data.
"""
try:
request = await self.omnikinverter.perform_request()
data: OmnikInverterData = {
SERVICE_INVERTER: await self.omnikinverter.inverter(),
SERVICE_DEVICE: await self.omnikinverter.device(),
SERVICE_INVERTER: request.inverter(),
SERVICE_DEVICE: request.device(),
}
return data
except OmnikInverterAuthError as error:
Expand Down

0 comments on commit a26b744

Please sign in to comment.