Skip to content

Commit

Permalink
added a warning when the PoolMath URL is improperly configured OR whe…
Browse files Browse the repository at this point in the history
…n PoolMath returns NO pools
  • Loading branch information
rsnodgrass committed Jun 17, 2022
1 parent 1b1cb63 commit bfc97c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/poolmath/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ def __init__(
):
"""Initialize the Pool Math service sensor."""
self.hass = hass
self._config = config

self._name = name

self._managed_sensors = {}
self._attrs = {
ATTR_ATTRIBUTION: ATTRIBUTION,
CONF_URL: config.get(CONF_URL)
CONF_URL: self._config.get(CONF_URL)
}

self._poolmath_client = poolmath_client
Expand Down Expand Up @@ -123,8 +125,14 @@ async def async_update(self):
LOG.warning(f"No PoolMath response, is your YAML configuration using the updated https://api prefix URLs?")
return


# update state attributes with relevant data
pool = poolmath_json.get('pools')[0].get('pool')
pools = poolmath_json.get('pools')
if not pools:
LOG.warning(f"PoolMath returned NO pools for the configured URL {self._config.get(CONF_URL)}. Please confirm your URL follows PoolMath's latest https://api.... URL format and properly works in your browser.")
return

pool = pools[0].get('pool')
self._attrs |= {
'name': pool.get('name'),
'volume': pool.get('volume')
Expand Down

0 comments on commit bfc97c6

Please sign in to comment.