Skip to content

Commit

Permalink
Merge branch 'usa'
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Apr 5, 2024
2 parents 6a36d90 + 8cccbf3 commit 41abc5c
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 112 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
4 changes: 2 additions & 2 deletions custom_components/carbu_com/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_schema(entry, option=False):
vol.Required("country", default=default_country, description="Country")
] = selector({
"select": {
"options": ['BE', 'DE', 'FR', 'IT', 'LU', 'NL','ES'],
"options": ['BE', 'DE', 'FR', 'IT', 'LU', 'NL','ES','US'],
"mode": "dropdown"
}
})
Expand Down Expand Up @@ -307,7 +307,7 @@ async def async_step_town(self, user_input=None): # pylint: disable=dangerous-d
self._init_info.update(user_input)
if user_input.get('individualstation') == True:
boundingboxLocationInfo = None
if self._init_info.get('country').lower() in ['it','nl','es']:
if self._init_info.get('country').lower() in ['it','nl','es','us']:
boundingboxLocationInfo = await self.hass.async_add_executor_job(lambda: self._session.convertLocationBoundingBox(self._init_info.get('postalcode'), self._init_info.get('country'), self._init_info.get('town')))
# self._stations = []
self._stations = await self.hass.async_add_executor_job(lambda: self._session.getFuelPrices(self._init_info.get('postalcode'), self._init_info.get('country'), self._init_info.get('town'), boundingboxLocationInfo, FuelType.DIESEL, False))
Expand Down
2 changes: 1 addition & 1 deletion custom_components/carbu_com/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/carbu_com/issues",
"requirements": ["bs4","requests","ratelimit"],
"version": "9.1.0"
"version": "10.0.0"
}
27 changes: 19 additions & 8 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 @@ -316,7 +318,7 @@ async def _forced_update(self):
self._city = self._carbuLocationInfo.get("pn")
self._countryname = self._carbuLocationInfo.get("cn")
self._locationinfo = self._carbuLocationInfo.get("id")
if self._locationinfo is None and self._country.lower() in ['it','nl','es']:
if self._locationinfo is None and self._country.lower() in ['it','nl','es', 'us']:
boundingboxLocationInfo = await self._hass.async_add_executor_job(lambda: self._session.convertLocationBoundingBox(self._postalcode, self._country, self._town))
self._locationinfo = boundingboxLocationInfo
# postalcode, country, town, locationinfo, fueltypecode)
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
6 changes: 3 additions & 3 deletions custom_components/carbu_com/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ get_lowest_fuel_price:
example: diesel
country:
description: >
The country to look for, supported options: BE / FR / LU / DE / IT
The country to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US
example: BE
postalcode:
description: >
Expand Down Expand Up @@ -65,7 +65,7 @@ get_lowest_fuel_price_on_route:
example: diesel
country:
description: >
The country to look for, supported options: BE / FR / LU / DE / IT
The country to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US
example: BE
from_postalcode:
description: >
Expand All @@ -77,7 +77,7 @@ get_lowest_fuel_price_on_route:
example: 3620
to_country:
description: >
(Optional) The country of target location to look for, supported options: BE / FR / LU / DE / IT, if no to_country is provided, country will be used same for source and target location
(Optional) The country of target location to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US, if no to_country is provided, country will be used same for source and target location
example: BE
filter:
description: >
Expand Down
16 changes: 8 additions & 8 deletions custom_components/carbu_com/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"user": {
"description": "Setup Carbu.com and Mazout.com sensors.",
"data": {
"country": "Country (BE/FR/LU/DE/IT)",
"country": "Country (BE / FR / LU / DE / IT / NL / ES / US)",
"postalcode": "Postal code",
"town": "Town",
"filter": "Supplier brand filter (optional)",
Expand All @@ -25,7 +25,7 @@
"edit": {
"description": "Setup Carbu.com and Mazout.com sensors.",
"data": {
"country": "Country (BE/FR/LU/DE/IT)",
"country": "Country (BE / FR / LU / DE / IT / NL / ES / US)",
"postalcode": "Postal code",
"town": "Town",
"filter": "Supplier brand filter (optional)",
Expand All @@ -40,7 +40,7 @@

},
"error": {
"missing country": "Please provide a valid country: BE/FR/LU/DE/IT",
"missing country": "Please provide a valid country: BE / FR / LU / DE / IT / NL / ES / US",
"missing postal code": "Please provide a valid postal code",
"missing data options handler": "Option handler failed",
"no_valid_settings": "No valid settings check in ha config."
Expand All @@ -51,7 +51,7 @@
"edit": {
"description": "Setup Carbu.com and Mazout.com sensors.",
"data": {
"country": "Country (BE/FR/LU/DE/IT)",
"country": "Country (BE / FR / LU / DE / IT / NL / ES / US)",
"postalcode": "Postal code",
"town": "Town",
"filter": "Supplier brand filter (optional)",
Expand All @@ -65,7 +65,7 @@
}
},
"error": {
"missing country": "Please provide a valid country: BE/FR/LU/DE/IT",
"missing country": "Please provide a valid country: BE / FR / LU / DE / IT / NL / ES / US",
"missing postal code": "Please provide a valid postal code",
"missing data options handler": "Option handler failed",
"no_valid_settings": "No valid settings check in ha config."
Expand All @@ -82,7 +82,7 @@
},
"country": {
"name": "country",
"description": "The country to look for, supported options: BE / FR / LU / DE / IT"
"description": "The country to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US"
},
"postalcode": {
"name": "postalcode",
Expand Down Expand Up @@ -138,7 +138,7 @@
},
"country": {
"name": "country",
"description": "The country to look for, supported options: BE / FR / LU / DE / IT"
"description": "The country to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US"
},
"from_postalcode": {
"name": "from_postalcode",
Expand All @@ -150,7 +150,7 @@
},
"to_country": {
"name": "to_country",
"description": "(Optional) The country of target location to look for, supported options: BE / FR / LU / DE / IT, if no to_country is provided, country will be used same for source and target location"
"description": "(Optional) The country of target location to look for, supported options: BE / FR / LU / DE / IT / NL / ES / US, if no to_country is provided, country will be used same for source and target location"
},
"filter": {
"name": "filter",
Expand Down
8 changes: 4 additions & 4 deletions custom_components/carbu_com/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"user": {
"description": "Setup Carbu.com and Mazout.com sensors.",
"data": {
"country": "Country (BE/DE/FR/IT/LU/NL/ES)",
"country": "Country (BE/DE/FR/IT/LU/NL/ES/US)",
"postalcode": "Postal code",
"filter": "Supplier brand filter (optional)",
"super95": "Super 95 (E10)",
Expand Down Expand Up @@ -38,7 +38,7 @@
}
},
"error": {
"missing country": "Please provide a valid country: BE/DE/FR/IT/LU/NL/ES",
"missing country": "Please provide a valid country: BE/DE/FR/IT/LU/NL/ES/US",
"missing postal code": "Please provide a valid postal code",
"missing data options handler": "Option handler failed",
"no_valid_settings": "No valid settings check in ha config."
Expand All @@ -64,7 +64,7 @@
}
},
"error": {
"missing country": "Please provide a valid country: BE/DE/FR/IT/LU/NL",
"missing country": "Please provide a valid country: BE/DE/FR/IT/LU/NL/ES/US",
"missing postal code": "Please provide a valid postal code",
"missing data options handler": "Option handler failed",
"no_valid_settings": "No valid settings check in ha config."
Expand All @@ -81,7 +81,7 @@
},
"country": {
"name": "country",
"description": "The country to look for, supported options: BE/DE/FR/IT/LU/NL"
"description": "The country to look for, supported options: BE/DE/FR/IT/LU/NL/ES/US"
},
"postalcode": {
"name": "postalcode",
Expand Down
12 changes: 6 additions & 6 deletions custom_components/carbu_com/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"config": {
"error": {
"missing country": "Veuillez fournir un pays valide: BE/DE/FR/IT/LU/NL",
"missing country": "Veuillez fournir un pays valide: BE/DE/FR/IT/LU/NL/ES/US",
"missing data options handler": "Le gestionnaire d'options a échoué",
"missing postal code": "Veuillez fournir un code postal valide",
"no_valid_settings": "Aucun paramètre valide trouvé dans la configuration HA."
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"user": {
"data": {
"country": "Pays (BE/DE/FR/IT/LU/NL/ES)",
"country": "Pays (BE/DE/FR/IT/LU/NL/ES/US)",
"diesel": "Diesel (B7)",
"filter": "Filtre marque fournisseur (facultatif)",
"logo_with_price": "Logo avec prix",
Expand All @@ -46,7 +46,7 @@
},
"options": {
"error": {
"missing country": "Veuillez fournir un pays valide: BE/DE/FR/IT/LU/NL",
"missing country": "Veuillez fournir un pays valide: BE/DE/FR/IT/LU/NL/ES/US",
"missing data options handler": "Le gestionnaire d'options a échoué",
"missing postal code": "Veuillez fournir un code postal valide",
"no_valid_settings": "Aucun paramètre valide trouvé dans la configuration HA."
Expand Down Expand Up @@ -75,7 +75,7 @@
"description": "Obtenez le prix du carburant le plus bas dans le voisinage d'un emplacement spécifique défini par le code postal et la ville (facultatif).",
"fields": {
"country": {
"description": "Le pays à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL",
"description": "Le pays à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL/ES/US",
"name": "country"
},
"filter": {
Expand Down Expand Up @@ -131,7 +131,7 @@
"description": "Obtenez le prix du carburant le plus bas sur un itinéraire entre 2 emplacements définis par des codes postaux",
"fields": {
"country": {
"description": "Le pays à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL",
"description": "Le pays à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL/ES/US",
"name": "country"
},
"filter": {
Expand All @@ -147,7 +147,7 @@
"name": "fuel_type"
},
"to_country": {
"description": "(Facultatif) Le pays de l'emplacement cible à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL, si aucun to_country n'est fourni, le pays sera utilisé de la même manière pour l'emplacement source et cible",
"description": "(Facultatif) Le pays de l'emplacement cible à rechercher, options prises en charge : BE/DE/FR/IT/LU/NL/ES/US, si aucun to_country n'est fourni, le pays sera utilisé de la même manière pour l'emplacement source et cible",
"name": "to_country"
},
"to_postalcode": {
Expand Down
12 changes: 6 additions & 6 deletions custom_components/carbu_com/translations/nl.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"config": {
"error": {
"missing country": "Geef een geldig land op: BE/DE/FR/IT/LU/NL",
"missing country": "Geef een geldig land op: BE/DE/FR/IT/LU/NL/ES/US",
"missing data options handler": "Fout bij het verwerken van de opties",
"missing postal code": "Geef een geldige postcode op",
"no_valid_settings": "Geen geldige instellingen gevonden in de configuratie."
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"user": {
"data": {
"country": "Land (BE/DE/FR/IT/LU/NL/ES)",
"country": "Land (BE/DE/FR/IT/LU/NL/ES/US)",
"diesel": "Diesel (B7)",
"filter": "Filter voor leveranciersmerk (optioneel)",
"logo_with_price": "Logo met prijs",
Expand All @@ -46,7 +46,7 @@
},
"options": {
"error": {
"missing country": "Geef een geldig land op: BE/DE/FR/IT/LU/NL",
"missing country": "Geef een geldig land op: BE/DE/FR/IT/LU/NL/ES/US",
"missing data options handler": "Fout bij het verwerken van de opties",
"missing postal code": "Geef een geldige postcode op",
"no_valid_settings": "Geen geldige instellingen gevonden in de configuratie."
Expand Down Expand Up @@ -75,7 +75,7 @@
"description": "Krijg de laagste brandstofprijs in de buurt van een specifieke locatie, gedefinieerd door postcode en stad (optioneel).",
"fields": {
"country": {
"description": "Het land om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL",
"description": "Het land om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL/ES/US",
"name": "country"
},
"filter": {
Expand Down Expand Up @@ -131,7 +131,7 @@
"description": "Krijg de laagste brandstofprijs op een route tussen 2 locaties gedefinieerd door postcodes",
"fields": {
"country": {
"description": "Het land om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL",
"description": "Het land om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL/ES/US",
"name": "country"
},
"filter": {
Expand All @@ -147,7 +147,7 @@
"name": "fuel_type"
},
"to_country": {
"description": "(Optioneel) Het land van de doellocatie om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL, als er geen to_country is opgegeven, wordt hetzelfde land gebruikt voor zowel de bron- als doellocatie",
"description": "(Optioneel) Het land van de doellocatie om naar te zoeken, ondersteunde opties: BE/DE/FR/IT/LU/NL/ES/US, als er geen to_country is opgegeven, wordt hetzelfde land gebruikt voor zowel de bron- als doellocatie",
"name": "to_country"
},
"to_postalcode": {
Expand Down
Loading

0 comments on commit 41abc5c

Please sign in to comment.