Skip to content

Commit

Permalink
5.0.0 support for German (DE) Fuel prices added
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Jul 16, 2023
1 parent 413ee6b commit feeb4df
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 74 deletions.
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/myTselection/carbu_com.svg)](https://github.com/myTselection/carbu_com/graphs/commit-activity)

# Carbu.com Home Assistant integration
[Carbu.com](https://www.Carbu.com/) Home Assistant custom component. This custom component has been built from the ground up to bring Carbu.com & Mazout.com site data to compare and save on your fuel oil, diesel and Super prices and integrate this information into Home Assistant to help you towards a better follow up. This integration is built against the public website provided by Carbu.com for Belgium and has not been tested for any other countries.

[Carbu.com](https://www.Carbu.com/) Home Assistant custom component. This custom component has been built from the ground up to bring Carbu.com & Mazout.com site data to compare and save on your fuel oil, diesel and Super prices and integrate this information into Home Assistant to help you towards a better follow up. This integration is built against the public website provided by Carbu.com.
This integration is in no way affiliated with Carbu.com.

Since R5.0, support for fuel prices in Germany (DE) has been added. City or postalcode can be provided as location.


Some discussion on this topic can be found within [the Home Assistant community forum](https://community.home-assistant.io/t/rest-sensor-needs-to-get-latest-element-of-list/404882/4).

For electricity price expectations [this Entso-E HACS integration](https://github.com/JaccoR/hass-entso-e) can be used.
Expand All @@ -22,12 +24,12 @@ For electricity price expectations [this Entso-E HACS integration](https://githu
- [HACS](https://hacs.xyz/): add url https://github.com/myTselection/carbu_com as custom repository (HACS > Integration > option: Custom Repositories)
- Restart Home Assistant
- Add 'Carbu.com' integration via HA Settings > 'Devices and Services' > 'Integrations'
- Provide country (currently only tested with BE), postal code and select the desired sensors
- If your postal code is not unique, the name of the town can be selected from the dropdown in the next step of the setup config flow. See [carbu.com](https://carbu.com) website for known towns and postal codes.
- Provide country, postal code and select the desired sensors
- If your postal code is not unique, the name of the town can be selected from the dropdown in the next step of the setup config flow. See [carbu.com](https://carbu.com) website for known towns and postal codes. (Not supported for DE)
- A filter on supplier brand name can be set (optional). If the filter match, the fuel station will be considered, else next will be searched. A python regex filter value be set

## Integration
- <details><summary>Sensor diesel and super <code>sensor.carbu_com_[fueltype]_[postalcode]_price</code> and fuel oil <code>sensor.carbu_com_[fueltype]_[postalcode]_[quantity]l_price</code></summary>
- <details><summary>Sensor diesel and super <code>sensor.carbu_com_[fueltype]_[postalcode]_price</code> and fuel oil <code>sensor.carbu_com_[fueltype]_[postalcode]_[quantity]l_price</code> Fuel oil only supported for BE/FR/LU</summary>

| Attribute | Description |
| --------- | ----------- |
Expand All @@ -37,7 +39,7 @@ For electricity price expectations [this Entso-E HACS integration](https://githu
| `fuelname` | Full name of the fuel type |
| `postalcode` | Postalcode at which the price was retrieved |
| **`supplier`** | **Name of the supplier of the fuel** |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) Not supported for DE |
| `url` | Url with details of the supplier |
| `entity_picture` | Url with the logo of the supplier |
| `address` | Address of the supplier |
Expand All @@ -62,13 +64,13 @@ For electricity price expectations [this Entso-E HACS integration](https://githu
| `fuelname` | Full name of the fuel type |
| `postalcode` | Postalcode at which the price was retrieved |
| `supplier` | Name of the supplier of the fuel |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) Not supported for DE |
| `url` | Url with details of the supplier |
| `entity_picture` | Url with the logo of the supplier |
| `address` | Address of the supplier |
| `city` | City of the supplier |
| `latitude` | Latitude of the supplier |
| `longitude` | Longitude of the supplier |
| `latitude` | Latitude of the supplier Not supported for DE |
| `longitude` | Longitude of the supplier Not supported for DE |
| `region` | Distand 5km or 10km around postal code in which cheapest prices is found |
| **`distance`** | **Distance to the supplier vs postal code** |
| **`price diff`** | **Price difference between the cheapest found in region versus the local price** |
Expand All @@ -79,7 +81,7 @@ For electricity price expectations [this Entso-E HACS integration](https://githu
| `score` | Score of the supplier |
</details>

- <details><summary>Sensor diesel and super prediction: <code>sensor.carbu_com_[fueltype]_prediction</code></summary>
- <details><summary>Sensor diesel and super prediction: <code>sensor.carbu_com_[fueltype]_prediction</code> Only supported for BE/FR/LU</summary>

| Attribute | Description |
| --------- | ----------- |
Expand All @@ -90,7 +92,7 @@ For electricity price expectations [this Entso-E HACS integration](https://githu
| `date` | Date for the validity of the price |
</details>

- <details><summary>Sensor fuel oil prediction: <code>sensor.carbu_com_[oiltype]_[quantity]l_prediction</code></summary>
- <details><summary>Sensor fuel oil prediction: <code>sensor.carbu_com_[oiltype]_[quantity]l_prediction</code> Only supported for BE/FR/LU</summary>

| Attribute | Description |
| --------- | ----------- |
Expand All @@ -115,13 +117,13 @@ A **service `carbu_com.get_lowest_fuel_price`** to get the lowest fuel price in
| `fuelname` | Full name of the fuel type |
| `postalcode` | Postalcode at which the price was retrieved |
| `supplier` | Name of the supplier of the fuel |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) Not supported for DE |
| `url` | Url with details of the supplier |
| `entity_picture` | Url with the logo of the supplier |
| `address` | Address of the supplier |
| `city` | City of the supplier |
| `latitude` | Latitude of the supplier |
| `longitude` | Longitude of the supplier |
| `latitude` | Latitude of the supplier Not supported for DE |
| `longitude` | Longitude of the supplier Not supported for DE |
| `region` | Distand 5km or 10km around postal code in which cheapest prices is found |
| **`distance`** | **Distance to the supplier vs postal code** |
| **`price diff`** | **Price difference between the cheapest found in region versus the local price** |
Expand Down Expand Up @@ -194,13 +196,13 @@ A **service `carbu_com.get_lowest_fuel_price_on_route`** (**BETA**) to get the l
| `fuelname` | Full name of the fuel type |
| `postalcode` | Postalcode at which the price was retrieved |
| `supplier` | Name of the supplier of the fuel |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) |
| `supplier_brand` | Brand name of the supplier (eg Shell, Texaco, ...) Not supported for DE |
| `url` | Url with details of the supplier |
| `entity_picture` | Url with the logo of the supplier |
| `address` | Address of the supplier |
| `city` | City of the supplier |
| `latitude` | Latitude of the supplier |
| `longitude` | Longitude of the supplier |
| `latitude` | Latitude of the supplier Not supported for DE |
| `longitude` | Longitude of the supplier Not supported for DE |
| `region` | Distand 5km or 10km around postal code in which cheapest prices is found |
| **`distance`** | **Distance to the supplier vs postal code** |
| **`price diff`** | **Price difference between the cheapest found in region versus the local price** |
Expand Down
11 changes: 9 additions & 2 deletions custom_components/carbu_com/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def create_schema(entry, option=False):
data_schema = OrderedDict()
data_schema[
vol.Required("country", default=default_country, description="Country")
] = str
] = selector({
"select": {
"options": ['BE','FR','LU','DE'],
"mode": "dropdown"
}
})
data_schema[
vol.Required("postalcode", default=default_postalcode, description="Postal Code")
] = str
Expand Down Expand Up @@ -91,7 +96,7 @@ def create_town_schema(towns):
"options": towns,
"mode": "dropdown"
}
})
})

return data_schema

Expand All @@ -117,6 +122,8 @@ async def async_step_user(self, user_input=None): # pylint: disable=dangerous-d
self._init_info = user_input
if not(self._session):
self._session = ComponentSession()
if user_input.get('country') == 'DE':
return self.async_create_entry(title=NAME, data=self._init_info)
carbuLocationInfo = await self.hass.async_add_executor_job(lambda: self._session.convertPostalCodeMultiMatch(user_input.get('postalcode'), user_input.get('country')))
if len(carbuLocationInfo) > 1:
for location in carbuLocationInfo:
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": "4.2.0"
"version": "5.0.0"
}
34 changes: 19 additions & 15 deletions custom_components/carbu_com/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ async def dry_setup(hass, config_entry, async_add_devices):
# await sensorSuper95Neigh.async_update()
sensors.append(sensorSuper95Neigh)

sensorSuper95Prediction = ComponentFuelPredictionSensor(componentData, FuelType.SUPER95_Prediction)
# await sensorSuper95Prediction.async_update()
sensors.append(sensorSuper95Prediction)
if country != 'DE':
sensorSuper95Prediction = ComponentFuelPredictionSensor(componentData, FuelType.SUPER95_Prediction)
# await sensorSuper95Prediction.async_update()
sensors.append(sensorSuper95Prediction)


if super98:
Expand Down Expand Up @@ -110,11 +111,12 @@ async def dry_setup(hass, config_entry, async_add_devices):
# await sensorDieselNeigh.async_update()
sensors.append(sensorDieselNeigh)

sensorDieselPrediction = ComponentFuelPredictionSensor(componentData, FuelType.DIESEL_Prediction)
# await sensorDieselPrediction.async_update()
sensors.append(sensorDieselPrediction)
if country != 'DE':
sensorDieselPrediction = ComponentFuelPredictionSensor(componentData, FuelType.DIESEL_Prediction)
# await sensorDieselPrediction.async_update()
sensors.append(sensorDieselPrediction)

if oilstd:
if oilstd and country != 'DE':
sensorOilstd = ComponentPriceSensor(componentData, FuelType.OILSTD, postalcode, True, quantity)
# await sensorOilstd.async_update()
sensors.append(sensorOilstd)
Expand All @@ -123,7 +125,7 @@ async def dry_setup(hass, config_entry, async_add_devices):
# await sensorOilstdPrediction.async_update()
sensors.append(sensorOilstdPrediction)

if oilextra:
if oilextra and country != 'DE':
sensorOilextra = ComponentPriceSensor(componentData, FuelType.OILEXTRA, postalcode, True, quantity)
# await sensorOilextra.async_update()
sensors.append(sensorOilextra)
Expand Down Expand Up @@ -203,7 +205,7 @@ def __init__(self, config, hass):

async def get_fuel_price_info(self, fuel_type: FuelType):
_LOGGER.debug(f"{NAME} getting fuel price_info {fuel_type.name_lowercase}")
price_info = await self._hass.async_add_executor_job(lambda: self._session.getFuelPrices(self._postalcode, self._country, self._town, self._locationid, fuel_type.code, False))
price_info = await self._hass.async_add_executor_job(lambda: self._session.getFuelPrices(self._postalcode, self._country, self._town, self._locationid, fuel_type, False))
self._price_info[fuel_type] = price_info
_LOGGER.debug(f"{NAME} price_info {fuel_type.name_lowercase} {price_info}")

Expand Down Expand Up @@ -239,7 +241,7 @@ async def _forced_update(self):

if self._session:
_LOGGER.debug("Starting with session for " + NAME)
if self._locationid is None:
if self._locationid is None and self._country != 'DE':
self._carbuLocationInfo = await self._hass.async_add_executor_job(lambda: self._session.convertPostalCode(self._postalcode, self._country, self._town))
self._town = self._carbuLocationInfo.get("n")
self._city = self._carbuLocationInfo.get("pn")
Expand All @@ -248,7 +250,8 @@ async def _forced_update(self):
# postalcode, country, town, locationid, fueltypecode)
if self._super95:
await self.get_fuel_price_info(FuelType.SUPER95)
await self.get_fuel_price_prediction_info(FuelType.SUPER95_Prediction)
if self._country != 'DE':
await self.get_fuel_price_prediction_info(FuelType.SUPER95_Prediction)
else:
_LOGGER.debug(f"{NAME} not getting fuel price_info {self._super95} FueltType.SUPER95.name_lowercase {FuelType.SUPER95.name_lowercase}")

Expand All @@ -257,15 +260,16 @@ async def _forced_update(self):

if self._diesel:
await self.get_fuel_price_info(FuelType.DIESEL)
await self.get_fuel_price_prediction_info(FuelType.DIESEL_Prediction)
if self._country != 'DE':
await self.get_fuel_price_prediction_info(FuelType.DIESEL_Prediction)

if self._oilstd:
if self._oilstd and self._country != 'DE':
await self.get_oil_price_info(FuelType.OILSTD)

if self._oilextra:
if self._oilextra and self._country != 'DE':
await self.get_oil_price_info(FuelType.OILEXTRA)

if self._oilstd or self._oilextra:
if self._oilstd or self._oilextra and self._country != 'DE':
await self.get_oil_price_prediction_info()

self._lastupdate = datetime.now()
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/FR/LU)",
"country": "Country (BE/FR/LU/DE)",
"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)",
"country": "Country (BE/FR/LU/DE)",
"postalcode": "Postal code",
"town": "Town",
"filter": "Supplier brand filter (optional)",
Expand All @@ -51,7 +51,7 @@
"edit": {
"description": "Setup Carbu.com and Mazout.com sensors.",
"data": {
"country": "Country (BE/FR/LU)",
"country": "Country (BE/FR/LU/DE)",
"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",
"missing country": "Please provide a valid country: BE/FR/LU/DE",
"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 Down
Loading

0 comments on commit feeb4df

Please sign in to comment.