Skip to content

Commit

Permalink
Merge pull request #39 from zener82/patch-1
Browse files Browse the repository at this point in the history
[Issue] sensor.py : fix issue when data is empty
  • Loading branch information
myTselection authored Dec 29, 2023
2 parents 9b5c4ca + 7c71efc commit 73d5046
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions custom_components/carbu_com/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,23 @@ async def async_update(self):

self._priceinfo = self._data._price_info.get(self._fueltype)
if self._isOil:
self._price = float(self._priceinfo.get("data")[0].get("unitPrice"))
self._supplier = self._priceinfo.get("data")[0].get("supplier").get("name") #x.data[0].supplier.name
oilproductid = self._fueltype.code
self._url = f"https://mazout.com/belgie/offers?areaCode={self._data._locationinfo}&by=quantity&for={self._quantity}&productId={oilproductid}"
self._logourl = self._priceinfo.get("data")[0].get("supplier").get("media").get("logo").get("src") #x.data[0].supplier.media.logo.src
self._score = self._priceinfo.get("data")[0].get("supplier").get("rating").get("score") #x.data[0].supplier.rating.score
# self._address =
# self._city =
# self._lat =
# self._lon =
self._fuelname = self._priceinfo.get("data")[0].get("product").get("name") #x.data[0].product.name
# self._distance =
self._date = self._priceinfo.get("data")[0].get("available").get("visible")# x.data[0].available.visible
# self._quantity = self._priceinfo.get("data")[0].get("quantity")
if len(self._priceinfo.get("data"))>0:
self._price = float(self._priceinfo.get("data")[0].get("unitPrice"))
self._supplier = self._priceinfo.get("data")[0].get("supplier").get("name") #x.data[0].supplier.name
oilproductid = self._fueltype.code
self._url = f"https://mazout.com/belgie/offers?areaCode={self._data._locationinfo}&by=quantity&for={self._quantity}&productId={oilproductid}"
self._logourl = self._priceinfo.get("data")[0].get("supplier").get("media").get("logo").get("src") #x.data[0].supplier.media.logo.src
self._score = self._priceinfo.get("data")[0].get("supplier").get("rating").get("score") #x.data[0].supplier.rating.score
# self._address =
# self._city =
# self._lat =
# self._lon =
self._fuelname = self._priceinfo.get("data")[0].get("product").get("name") #x.data[0].product.name
# self._distance =
self._date = self._priceinfo.get("data")[0].get("available").get("visible")# x.data[0].available.visible
# self._quantity = self._priceinfo.get("data")[0].get("quantity")
else:
_LOGGER.debug(f'No data available in priceinfo')
else:
# _LOGGER.debug(f'indiv. station: {self._individual_station}')
stationInfo = await self._data.getStationInfoFromPriceInfo(self._priceinfo, self._postalcode, self._fueltype, 0, self._data._filter, self._individual_station)
Expand Down Expand Up @@ -1003,4 +1006,4 @@ def device_class(self):
@property
def friendly_name(self) -> str:
return self.unique_id.title()


0 comments on commit 73d5046

Please sign in to comment.