Code Monkey home page Code Monkey logo

fuelprices_dk's Introduction

hacs_badge GitHub release (latest by date) GitHub all releases GitHub last commit GitHub code size in bytes Buy me a coffee

Fuelprices DK

Introduction

With Fuelprices_DK it is possible to track fuelprices in Denmark.

Installation

HACS

This integration has been approved to the default HACS repository

Custom integration in HACS

https://hacs.xyz/docs/faq/custom_repositories

Configuration

In the default configuration it will track the following fueltypes:

  • Octane 95
  • Octane 95+ (additives)
  • Octane 100
  • Diesel
  • Diesel+ (additives)
  • Electric

From these fuelcompanies:

  • Circle K
  • F24
  • Go'On
  • ingo
  • OIL! tank & go
  • OK
  • Q8
  • Shell

Configuration

fuelprices_dk:
  # Optional entries
  # Bypass the default update interval (60 minutes)
  update_interval: 300
  companies:
  # possible values are: circlek, f24, goon, ingo, oil, ok, q8 and shell
    - ok
    - shell
  fueltypes:
  # Possible values are: oktan 95, oktan 95+, oktan 100, diesel, diesel+ and electric
    - oktan 95
    - diesel

fuelprices_dk's People

Contributors

j-lindvig avatar larsalthof avatar vaerum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fuelprices_dk's Issues

Listprices instead of pumpprices

Hi J-Lindvig
I really appreciate your script - I have done an attempt to do it by myself without luck.
I would really like the Q8 Listprices instead of the pumpprices
I figured it was product 22351 for Oktan 95
And 24450 for Diesel - But as i've tried to add these to your script it does not work unfortunately.

Hope perhaps you could add these in the near future.

List index out of range

All sensors shows up with “unavailable” And I’m getting this in the log:

This error originated from a custom integration.

Logger: custom_components.fuelprices_dk.sensor
Source: custom_components/fuelprices_dk/fuelprices_dk_parsers.py:128 
Integration: Fuelprices DK (documentation, issues) 
First occurred: 11:12:54 AM (1 occurrences) 
Last logged: 11:12:54 AM

Unexpected error fetching sensor data: list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/fuelprices_dk/sensor.py", line 30, in async_update_data
    await hass.async_add_executor_job(fuelPrices.refresh)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 151, in refresh
    company.refreshPrices()
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 203, in refreshPrices
    self._products = getattr(self._parser, self._key)(self._url, self._products)
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 128, in oil
    priceSegments = cells[2].findAll(
IndexError: list index out of range

Virker denne integration

Denne integration ser ikke ud til at virke, måske der er et behov for yderligere detaljer vedr. installation - fx. hvor skal Config data skrives?

KeyError: 'price'

In HA 2023.5.2 I get the following errors in the log (sensors are not updated):

First occurred: 8. maj 2023 kl. 13.29.09 (32 occurrences)
Last logged: 21.44.45

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 204, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 349, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 146, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 585, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
if (state := self.state) is None:
File "/config/custom_components/fuelprices_dk/sensor.py", line 91, in state
return float(self._fuelCompany.getProductPrice(self._productKey))
File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 215, in getProductPrice
return self._products[productKey]["price"]
KeyError: 'price'

oil-tankstationer.dk parser failing

Hi,

It looks like https://www.oil-tankstationer.dk/de-gaeldende-braendstofpriser/ is breaking this integration. Which results in all fuelprices being unavailable. It seams like the required span tag (line 131) has been removed on their website.

def oil(self, url, products):
r = self._get_website(url)
html = self._get_html_soup(r)
rows = html.find_all("tr")
for productKey, productDict in products.items():
found = False
for row in rows:
if found:
continue
cells = row.find_all("td")
if cells:
found = productDict["name"] == self._cleanProductName(cells[0].text)
if found:
priceSegments = cells[2].findAll(
"span", style=["text-align:right;", "text-align:left;"]
)
products[productKey] = self._addPriceToProduct(
productDict,
priceSegments[0].text + "." + priceSegments[1].text,
)
return products

2023-08-01 17:40:39.131 ERROR (MainThread) [custom_components.fuelprices_dk.sensor] Unexpected error fetching sensor data: list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 242, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/sensor.py", line 39, in async_update_data
    await hass.async_add_executor_job(company.refreshPrices)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 202, in refreshPrices
    self._products = getattr(self._parser, self._key)(self._url, self._products)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 135, in oil
    priceSegments[0].text + "." + priceSegments[1].text,

Temporary fix for:

if found:
priceSegments = cells[2].findAll(
"span", style=["text-align:right;", "text-align:left;"]
)
products[productKey] = self._addPriceToProduct(
productDict,
priceSegments[0].text + "." + priceSegments[1].text,
)
return products

  if found:
    priceSegments = cells[2].findAll( 
      "span", style=["text-align:right;", "text-align:left;"] 
    )
+   if priceSegments:
+     products[productKey] = self._addPriceToProduct( 
+       productDict, 
+       priceSegments[0].text + "." + priceSegments[1].text, 
+     )
  return products 

Unable to get prices

I receive a number of errors:

This error originated from a custom integration.

Logger: custom_components.fuelprices_dk.sensor
Source: helpers/update_coordinator.py:262
Integration: Fuelprices DK (documentation, issues)
First occurred: 09:12:28 (1 occurrences)
Last logged: 09:12:28

Error requesting sensor data: HTTPSConnectionPool(host='www.f24.dk', port=443): Max retries exceeded with url: /-/api/PriceViewProduct/GetPriceViewProducts (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fde3cc64410>: Failed to establish a new connection: [Errno -3] Try again'))

Logger: homeassistant.components.sensor
Source: runner.py:179
Integration: Sensor (documentation, issues)
First occurred: 09:12:14 (1 occurrences)
Last logged: 09:12:17

Setup of sensor platform fuelprices_dk is taking over 10 seconds.

Integration is using deprecated `DEVICE_CLASS_*` constants

This custom integration uses deprecated DEVICE_CLASS_* constants in its codebase.

The DEVICE_CLASS_* constants have been deprecated and replaced in Home Assistant Core 2021.12 (over a year ago). I would highly suggest updating/migrating this integration to the new enums.

For example, for the device classes supported by the sensor platform, there is now a SensorDeviceClass enum. So if a sensor previously used the DEVICE_CLASS_ENERGY constant, it should now use SensorDeviceClass.ENERGY. Other platforms (like binary_sensor, and number) provide similar enumerations for their supported device classes.

The migration thus only consists of replacing constants with an enumeration member and is, therefore, very low impact and should be fairly straightforward.

If I can help resolve any questions regarding this change or migration, feel free to ask or respond to this issue. I'm happy to help!

Kindest regards,

../Frenck

"Go' on Blyfri 95" fails when parsing

Hi,

There seams to be a problem with parsing Go' on Blyfri 95 fuel prices (octane 95). The Go' on page does exist and seams to have valid content and fuel prices: https://goon.nu/priser/#Aktuellelistepriser

"goon": {
"name": "Go' on",
"url": "https://goon.nu/priser/#Aktuellelistepriser",
"products": {
OCTANE_95: {"name": "Blyfri 95", "ocr_crop": ["58", "232", "134", "46"]},
DIESEL: {"name": "Transportdiesel", "ocr_crop": ["58", "289", "134", "46"]},
},
},

HA log entry (and Go' on is the only one marked as unavailable):

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 316, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 556, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 597, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 562, in _stringify_state
    if (state := self.state) is None:
  File "/config/custom_components/fuelprices_dk/sensor.py", line 91, in state
    return float(self._fuelCompany.getProductPrice(self._productKey))
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 215, in getProductPrice
    return self._products[productKey]["price"]
KeyError: 'price'

Looks like the key price doesn't exist for Go' on Blyfri 95.

return self._products[productKey]["price"]

Uno-x

Would it be possible Aldi to include Uno-X to the list, that would be much appreciated.

Detected blocking call to sleep inside the event loop

Hi There,

Thanks for the integration. :)

Wanted to let you know with the new release of HA 2022.12 I noticed in the logs that the integrations complains and it tells me to inform you about it.

Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for fuelprices_dk doing blocking calls at custom_components/fuelprices_dk/sensor.py, line 36: time.sleep(3)

now it's reported :)

Best regards.

filter out values

how do I filter out values ?
I get all values i HA

my code :

fuelprices_dk:

Optional entries

companies:

possible values are: circlek, f24, goon, ingo, oil, ok, q8 and shell

- ingo
- shell

fueltypes:

Possible values are: oktan 95, oktan 95+, oktan 100, diesel, diesel+

- oktan 95
- oktan 95+

Uno-X

Any plan on Integrated Uno-X

Numeric values

Great plugin - now I'll know in advance that prices are on the rise once again :)

It seems the values are interpreted as strings, not numbers:
billede

It looks the same as for example a pressure sensor - but does not act the same...
billede

Maybe adding a "unit_of_measurement" would solve it? Or is the issue related to the "[object Object][object Object][object Object]" shown on the card?

No Issue - just trying to reach out

Hi

Came across this repo on HACS so I thot I'd reach out.

I am someone trying to learn how to write custom integrations for HA and contribute back to the community. There aren't a lot of India-specific integrations in HA and not a lot of contributors. I am trying to change that.
I have tried looking at the dev docs too, but somehow it never made sense to me.

Would you be willing to get on zoom to help me get started on a similar integration for fuel prices for India? I have an API that I can poll but that's practically all I have.

Rishab

F24 and Q8 down/slow. Parse error

Hi,

Thanks for this awesome HA extension!

It looks like F24 and Q8 API endpoints are very slow (randomly) at the moment ("" returned from API's). Which results in all fuel prices will be marked as Unavailable.

image

This causes multiple timeouts/errors in HA logs:

2022-11-03 08:23:19.212 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform fuelprices_dk is taking over 10 seconds.
2022-11-03 08:24:05.509 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: sensor.fuelprices_dk
2022-11-03 08:24:09.214 ERROR (MainThread) [homeassistant.components.sensor] Setup of platform fuelprices_dk is taking longer than 60 seconds. Startup will proceed without waiting any longer.
2022-11-03 08:24:55.064 ERROR (MainThread) [custom_components.fuelprices_dk.sensor] Unexpected error fetching sensor data: list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/fuelprices_dk/sensor.py", line 30, in async_update_data
    await hass.async_add_executor_job(fuelPrices.refresh)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 151, in refresh
    company.refreshPrices()
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 200, in refreshPrices
    self._products = getattr(self._parser, self._key)(self._url, self._products)
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 149, in f24
    return self._f24_q8(url, products)
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 182, in _f24_q8
    json_product = r.json()["Products"][productDict["Index"]]
IndexError: list index out of range

Would it maybe be an option to add the timeout argument to the request.get() and validate, that you get any content back in the response. The status is 200 - but no content.

def _get_website(self, url):
r = self._session.get(url)
_LOGGER.debug("URL: " + url + " [" + str(r.status_code) + "]")
if r.status_code != 200:
return r.status_code
return r

I guess r.text is valid, but it is empty.

def _get_html_soup(self, r, parser="html.parser"):
if r.text:
return BS(r.text, parser)

henter ikke priser siden d 10 august

Hej Jacob.

Først tak for dit store arbejde som kan hjælpe alle os andre.

Jeg ved ikke om det er mit system den er gal med eller hvad der sker for jeg kan se mit ha ikke har kunne hente rigtig pris den sidste lille uge sidst den kom med rigig pris var d 10 august

image
image

Detected blocking call to sleep inside the event loop...

Hej Jakob

For denne fejl i loggen:

Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for fuelprices_dk doing blocking calls at custom_components/fuelprices_dk/sensor.py, line 36: time.sleep(3)

Connecting problems

Jeg får denne fejl når HA starter.

This error originated from a custom integration.

Logger: custom_components.fuelprices_dk.sensor
Source: helpers/update_coordinator.py:151
Integration: Fuelprices DK (documentation, issues)
First occurred: September 25, 2022 at 10:57:47 (17 occurrences)
Last logged: 19:58:51

Error requesting sensor data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Unexpected error fetching sensor data: 'int' object has no attribute 'text'

Unexpected error fetching sensor data: 'int' object has no attribute 'text'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 293, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 248, in _async_update_data
return await self.update_method()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/fuelprices_dk/sensor.py", line 39, in async_update_data
await hass.async_add_executor_job(company.refreshPrices)
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 202, in refreshPrices
self._products = getattr(self._parser, self._key)(self._url, self._products)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 93, in shell
return self._getDataFromTable(url, products, 0, -1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 202, in _getDataFromTable
html = self._get_html_soup(r)
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 197, in _get_html_soup
if r.text:
^^^^^^
AttributeError: 'int' object has no attribute 'text'

Cirkle K

Jeg får ingen pris på Cirkle K oktan 95 der står bare utilgængelig. men der er ikke problmer med de andre selskaber

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.