Skip to content

Commit

Permalink
Added error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
freakshock88 committed Nov 19, 2019
1 parent e1298cc commit 3c64648
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions custom_components/populartimes/sensor.py
Expand Up @@ -5,9 +5,12 @@
from homeassistant.helpers.entity import Entity
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
import homeassistant.helpers.config_validation as cv
import logging
import populartimes
import voluptuous as vol

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_API_KEY): cv.string,
Expand Down Expand Up @@ -69,12 +72,6 @@ def update(self):
self._id
)

try:
current_popularity = result["current_popularity"]
self._state = current_popularity
except:
self._state = 0

self._attributes['address'] = result["address"]
self._attributes['maps_name'] = result["name"]
self._attributes['popularity_monday'] = result["populartimes"][0]["data"]
Expand All @@ -84,7 +81,9 @@ def update(self):
self._attributes['popularity_friday'] = result["populartimes"][4]["data"]
self._attributes['popularity_saturday'] = result["populartimes"][5]["data"]
self._attributes['popularity_sunday'] = result["populartimes"][6]["data"]
except (ConnectError, HTTPError, Timeout, ValueError) as error:
_LOGGER.error(
"Unable to connect to Google Place API: %s", error)
self._state = None

popularity = result.get('current_popularity')
self._state = popularity

except:
_LOGGER.error("No popularity info is returned by the populartimes library.")

0 comments on commit 3c64648

Please sign in to comment.