from .const import DOMAIN, URL_API_PREFIX from datetime import timedelta from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle import logging MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5) _LOGGER = logging.getLogger(__name__) async def api_call(session, url, data={}): return await session.async_request(method="GET", url=f"{URL_API_PREFIX}/{url}", json=data).json() class OndiloData: def __init__(self, session): self._session = session @Throttle(MIN_TIME_BETWEEN_UPDATES) async def async_update(self): pass class PHSensor(Entity): def __init__(self, data): self._data = data async def async_update(self): self._data.async_update() class ORPSensor(Entity): def __init__(self, data): self._data = data async def async_update(self): self._data.async_update() async def async_setup_entry(hass, entry, async_add_entities): session = hass.data[DOMAIN]['session'] res = await api_call(session, "pools") print(res) _LOGGER.warn(res) # data = OndiloData(session) # get pools # sensors = [PHSensor(data), ORPSensor(data)] # async_add_entities(sensors)