Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Apr 5, 2024
1 parent 41bb77d commit 8cccbf3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/carbu_com/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/carbu_com/issues",
"requirements": ["bs4","requests","ratelimit","uuid","re","urllib3"],
"requirements": ["bs4","requests","ratelimit"],
"version": "10.0.0"
}
25 changes: 18 additions & 7 deletions custom_components/carbu_com/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def __init__(self, config, hass):
self._town = config.get("town")
self._filter = config.get("filter","")
self._logo_with_price = config.get("logo_with_price", True)
self._price_unit = "€" if self._country.lower() != "us" else "$"
self._price_unit_per = "€/l" if self._country.lower() != "us" else "$/g"


self._friendly_name_price_template = config.get("friendly_name_price_template","")
Expand Down Expand Up @@ -416,6 +418,8 @@ def __init__(self, data, fueltype: FuelType, postalcode, isOil, quantity, indivi
self._date = None
self._score = None
self._country = data._country
self._price_unit = data._price_unit
self._price_unit_per = data._price_unit_per
self._id = None

@property
Expand Down Expand Up @@ -469,6 +473,7 @@ async def async_update(self):
self._date = stationInfo.get("date")
self._country = stationInfo.get("country")
self._id = stationInfo.get("id")
self._score = stationInfo.get("score")


async def async_will_remove_from_hass(self):
Expand Down Expand Up @@ -550,7 +555,7 @@ def unit(self) -> int:
@property
def unit_of_measurement(self) -> str:
"""Return the unit of measurement this sensor expresses itself in."""
return "€/l"
return self._price_unit_per

@property
def device_class(self):
Expand Down Expand Up @@ -586,6 +591,8 @@ def __init__(self, data, fueltype: FuelType, postalcode, max_distance):
self._diffPct = None
self._country = data._country
self._id = None
self._price_unit = data._price_unit
self._price_unit_per = data._price_unit_per

@property
def state(self):
Expand Down Expand Up @@ -668,9 +675,9 @@ def extra_state_attributes(self) -> dict:
"longitude": self._lon,
"region": f"{self._max_distance}km",
"distance": f"{self._distance}km",
"price diff": f"{self._diff}",
"price diff": f"{self._diff}{self._price_unit}",
"price diff %": f"{self._diffPct}%",
"price diff 30l": f"{self._diff30}",
"price diff 30l": f"{self._diff30}{self._price_unit}",
"date": self._date,
"score": self._score,
"filter": self._data._filter,
Expand Down Expand Up @@ -699,7 +706,7 @@ def unit(self) -> int:
@property
def unit_of_measurement(self) -> str:
"""Return the unit of measurement this sensor expresses itself in."""
return "€/l"
return self._price_unit_per

@property
def device_class(self):
Expand Down Expand Up @@ -817,6 +824,8 @@ def __init__(self, data, fueltype: FuelType, quantity):
self._date = None
self._officialPriceToday = None
self._officialPriceTodayDate = None
self._price_unit = data._price_unit
self._price_unit_per = data._price_unit_per


@property
Expand Down Expand Up @@ -903,9 +912,9 @@ def extra_state_attributes(self) -> dict:
"fueltype": self._fueltype.name_lowercase.split('_')[0].title(),
"fuelname": self._fuelname,
"trend": self._trend,
"price": f"{self._price}",
"price": f"{self._price}{self._price_unit}",
"date": self._date,
"current official max price": f"{self._officialPriceToday} €/l",
"current official max price": f"{self._officialPriceToday} {self._price_unit_per}",
"current official max price date": {self._officialPriceTodayDate},
"quantity": self._quantity
}
Expand Down Expand Up @@ -950,6 +959,8 @@ def __init__(self, data, fueltype):
self._date = None
self._priceNext = None
self._dateNext = None
self._price_unit = data._price_unit
self._price_unit_per = data._price_unit_per

self._friendly_name_official_template = self._data._friendly_name_official_template
self._friendly_name_official_template_choice = self._data._friendly_name_official_template_choice
Expand Down Expand Up @@ -1035,7 +1046,7 @@ def unit(self) -> int:
@property
def unit_of_measurement(self) -> str:
"""Return the unit of measurement this sensor expresses itself in."""
return "€/l"
return self._price_unit_per

@property
def device_class(self):
Expand Down
4 changes: 3 additions & 1 deletion custom_components/carbu_com/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ def getFuelPricesUS(self, postalcode, country, town, locationinfo, fueltype: Fue
date = matching_fuel_product.get("credit", {}).get("posted_time")
lat = block.get('info').get('latitude')
lon = block.get('info').get('longitude')
score = block.get('info').get('star_rating')


block_data = {
Expand All @@ -707,6 +708,7 @@ def getFuelPricesUS(self, postalcode, country, town, locationinfo, fueltype: Fue
'price': price_text,
# 'price_changed': price_changed,
'lat': lat,
'score': score,
'lon': lon,
'fuelname': fueltype.name,
'distance': distance,
Expand Down Expand Up @@ -1320,7 +1322,7 @@ def haversine_distance(self, lat1, lon1, lat2, lon2):
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

# Calculate the distance
distance = earth_radius * c
distance = round(earth_radius * c, 2)

return distance

Expand Down

0 comments on commit 8cccbf3

Please sign in to comment.