Skip to content

Commit

Permalink
chnges for test
Browse files Browse the repository at this point in the history
  • Loading branch information
jontofront committed Nov 14, 2024
1 parent abe0a07 commit 97cb63b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
55 changes: 37 additions & 18 deletions custom_components/econet300/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,6 @@ async def get_param_limits(self, param: str):
curr_limits = limits[param]
return Limits(curr_limits["min"], curr_limits["max"])

async def fetch_reg_params(self) -> dict[str, Any]:
"""Fetch and return the regParam data from ip/econet/regParams endpoint."""
_LOGGER.info("Calling fetch_reg_params method")
regParams = await self._client.get_params(API_REG_PARAMS_URI)
_LOGGER.debug("Fetched regParams data: %s", regParams)

if API_REG_PARAMS_PARAM_DATA in regParams:
_LOGGER.info(
"Response contains expected keys. API_REG_PARAMS_PARAM_DATA: %s",
regParams[API_REG_PARAMS_PARAM_DATA],
)
else:
_LOGGER.warning(
"Response does not contain expected keys. API_REG_PARAMS_PARAM_DATA is missing."
)

return regParams

async def fetch_data(self) -> dict[str, Any]:
"""Fetch data from regParamsData."""
regParamsData = await self._fetch_reg_key(
Expand Down Expand Up @@ -343,6 +325,43 @@ async def _fetch_reg_key(self, reg, data_key: str | None = None):

return data[data_key]

async def fetch_reg_params(self) -> dict[str, Any]:
"""Fetch and return the regParam data from ip/econet/regParams endpoint."""
_LOGGER.info("Calling fetch_reg_params method")
regParams = await self._fetch_reg_names(
API_REG_PARAMS_URI, API_REG_PARAMS_PARAM_DATA
)
_LOGGER.debug("Fetched regParams data: %s", regParams)

if API_REG_PARAMS_PARAM_DATA in regParams:
_LOGGER.info(
"Response contains expected keys. API_REG_PARAMS_PARAM_DATA: %s",
regParams[API_REG_PARAMS_PARAM_DATA],
)
else:
_LOGGER.warning(
"Response does not contain expected keys. API_REG_PARAMS_PARAM_DATA is missing."
)
_LOGGER.debug("Full response data: %s", regParams)

return regParams

async def _fetch_reg_names(self, reg, data_key_key_name: str | None = None):
"""Fetch a key from the json-encoded data returned by the API for a given registry If key is None, then return whole data."""
data = await self._client.get_params(reg)

if data is None:
raise DataError(f"Data fetched by API for reg: {reg} is None")

if data_key_key_name is None:
return data

if data_key_key_name not in data:
_LOGGER.debug(data)
raise DataError(f"Data for key: {data_key_key_name} does not exist")

return data[data_key_key_name]


async def make_api(hass: HomeAssistant, cache: MemCache, data: dict):
"""Create api object."""
Expand Down
5 changes: 4 additions & 1 deletion custom_components/econet300/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common code for econet300 integration."""

import asyncio
from datetime import timedelta
import logging
Expand Down Expand Up @@ -43,7 +44,9 @@ async def _async_update_data(self):
# Note: asyncio.TimeoutError and aiohttp.ClientError are already
# handled by the data update coordinator.
async with asyncio.timeout(10):
return await self._api.fetch_data()
data = await self._api.fetch_data()
reg_params = await self._api.fetch_reg_params()
return data, reg_params
except AuthError as err:
raise ConfigEntryAuthFailed from err
except ApiError as err:
Expand Down

0 comments on commit 97cb63b

Please sign in to comment.