class UntappdWishlistSensor(Entity): def __init__(self, hass, username, api_id, api_secret): from pyuntappd import Untappd self.hass = hass self._untappd = Untappd() self._username = username self._apiid = api_id self._apisecret = api_secret self._total_wishlist = None self._state = None self.hass.data[WISHLIST_DATA] = {} self.update() def update(self): result = self._untappd.get_wishlist( self._apiid, self._apisecret, self._username ) if not result: return False else: self._state = result["count"] for beer in result["items"]: name = beer["beer"]["beer_name"] self.hass.data[WISHLIST_DATA][name] = { "beer_name": name, "beer_label": beer["beer"]["beer_label"], "beer_description": beer["beer"]["beer_description"], "beer_abv": beer["beer"]["beer_abv"], "beer_style": beer["beer"]["beer_style"], "beer_ibu": beer["beer"]["beer_ibu"], "beer_link": "https://untappd.com/b/" + beer["beer"]["beer_slug"] + "/" + str(beer["beer"]["bid"]), "rating_score": beer["beer"]["rating_score"], "rating_count": beer["beer"]["rating_count"], "brewery_label": beer["brewery"]["brewery_label"], "brewery_name": beer["brewery"]["brewery_name"], "country_name": beer["brewery"]["country_name"], } @property def name(self): return "Untappd Wishlist (" + self._username + ")" @property def state(self): return self._state @property def icon(self): return ICON @property def extra_state_attributes(self): return self.hass.data[WISHLIST_DATA]
class UntappdWishlistSensor(Entity): def __init__(self, hass, username, api_id, api_secret): from pyuntappd import Untappd self.hass = hass self._untappd = Untappd() self._username = username self._apiid = api_id self._apisecret = api_secret self._total_wishlist = None self._state = None self.hass.data[WISHLIST_DATA] = {} self.update() def update(self): result = self._untappd.get_wishlist(self._apiid, self._apisecret, self._username) if not result: return False else: self._state = result['count'] for beer in result['items']: name = beer['beer']['beer_name'] self.hass.data[WISHLIST_DATA][name] = { "beer_name": name, "beer_label": beer['beer']['beer_label'], "beer_description": beer['beer']['beer_description'], "beer_abv": beer['beer']['beer_abv'], "beer_style": beer['beer']['beer_style'], "beer_ibu": beer['beer']['beer_ibu'], "beer_link": 'https://untappd.com/b/' + beer['beer']['beer_slug'] + '/' + str(beer['beer']['bid']), "rating_score": beer['beer']['rating_score'], "rating_count": beer['beer']['rating_count'], "brewery_label": beer['brewery']['brewery_label'], "brewery_name": beer['brewery']['brewery_name'], "country_name": beer['brewery']['country_name'], } @property def name(self): return 'Untappd Wishlist (' + self._username + ')' @property def state(self): return self._state @property def icon(self): return ICON @property def device_state_attributes(self): return self.hass.data[WISHLIST_DATA]