pantherale0 / ha-fuelprices

A generic and extensible integration with pyfuelprices to retrieve local (or remote) fuel price data.
MIT License
19 stars 2 forks source link

Manually update prices #8

Closed MaasOne closed 7 months ago

MaasOne commented 8 months ago

Checklist

Is your feature request related to a problem? Please describe.

The prices are only updated once a day. Since a price change one time per day is intended by law in a lot of countries, in Germany a gas station can change its prices whenever they want. So at least in Germany the prices are changing significantly over the day for every gas station. It's a short-term market. Also for once-a-day-countries the update time is important. Actually the update time is the time when the integration was configured. Not the time when the price can be changed by law. So, also for these countries at least an update time per day configuration would be great.

Describe the solution you'd like

Please integrate the possibility to update the prices manually. Either by giving the opportunity to update an entity with the service "homeassistant.update_entity" or with some other kind of input_button or service or so to trigger a complete update.

Describe alternatives you've considered

Additionally or as replacement you could give the option of amount of hours between updates and the "initial" time of update.

Additional context

None additional context.

pantherale0 commented 8 months ago

Hi,

I need to be careful enabling this as some providers seem to block IP addresses if an update is requested too often (https://community.home-assistant.io/t/fuel-prices-integration/658716/54?u=11harveyj), currently I have no idea what service limits are in place for some providers.

One provider in the UK will only allow you to request the data once every 24 hours for example, the rest will timeout.

The update interval can be configured down to a lowest of two hours (although the latest beta admittedly allows down to every 1 minute currently which will be far too often as you run a higher risk getting blocked I think).

MaasOne commented 8 months ago

Yes, updating every entity by itself would cause a lot of traffic and requests. So a regular update of all entities at the same time within a day would be great. Either by manual update of the user or by configuration.

For German "Tankerkoenig" I can tell you that a call every 3 hours is not a problem.

I'm actually updating every entity at once with homeassistant.reload_config_entry service with help of a specific static entity (device_tracker). This is just a workaround and shouldn't be intentionally.

I guess you need to test this out for every provider. Minimum every 1 hour would be great. At least every 3 hours should be provided where it's possible.

You don't need to implement a regulation below "every hour". It would be enough to write down in the documentation, which provider gives you an IP block at which interval. The rest is in the responsibility of the user. Of course you're also indirectly in responsibility with your software, but you can limit it to 1 time per hour. And that seems definitely to be enough for an API and at the same time for the need of these information.