rnovacek / homeassistant_cz_energy_spot_prices

Home Assistant integration that provides current Czech electricity spot prices based on OTE.
Apache License 2.0
75 stars 17 forks source link

Timezone issues #30

Open rnovacek opened 11 months ago

rnovacek commented 11 months ago

There are some problems if the current timezone is different than Europe/Prague.

For example with London timezone, this error occurs:

2023-07-12 13:52:06.736 ERROR (MainThread) [custom_components.cz_energy_spot_prices.coordinator] Unexpected error fetching Czech Energy Spot Prices - 1 data: datetime.datetime(2023, 7, 11, 23, 0, tzinfo=datetime.timezone.utc)
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 "/config/custom_components/cz_energy_spot_prices/coordinator.py", line 213, in _async_update_data
    gas=DailySpotRateData(gas_rates, zoneinfo=zoneinfo),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/cz_energy_spot_prices/coordinator.py", line 144, in __init__
    self._today = rates[midnight_today]
                  ~~~~~^^^^^^^^^^^^^^^^
KeyError: datetime.datetime(2023, 7, 11, 23, 0, tzinfo=datetime.timezone.utc)

Workaround is to set the timezone to Europe/Prague.

S474N commented 9 months ago

I have Europe/Prague in homeassistant.yaml but have same error:

KeyError: datetime.datetime(2023, 9, 30, 22, 0, tzinfo=datetime.timezone.utc)
2023-10-01 10:29:20.481 DEBUG (MainThread) [custom_components.cz_energy_spot_prices.coordinator] Finished fetching Czech Energy Spot Prices data in 0.164 seconds (success: False)
2023-10-01 10:30:40.788 DEBUG (MainThread) [custom_components.cz_energy_spot_prices] async_setup_entry None data: [{'currency': 'CZK', 'unit_of_measurement': 'kWh'}]; options: [{}]
2023-10-01 10:30:40.788 DEBUG (MainThread) [custom_components.cz_energy_spot_prices.coordinator] SpotRateCoordinator.__init__
2023-10-01 10:30:40.789 DEBUG (MainThread) [custom_components.cz_energy_spot_prices.coordinator] SpotRateCoordinator._async_update_data
2023-10-01 10:30:42.037 ERROR (MainThread) [custom_components.cz_energy_spot_prices.coordinator] Unexpected error fetching Czech Energy Spot Prices data: datetime.datetime(2023, 9, 30, 22, 0, tzinfo=datetime.timezone.utc)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/cz_energy_spot_prices/coordinator.py", line 213, in _async_update_data
    gas=DailySpotRateData(gas_rates, zoneinfo=zoneinfo),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/cz_energy_spot_prices/coordinator.py", line 144, in __init__
    self._today = rates[midnight_today]
                  ~~~~~^^^^^^^^^^^^^^^^
S474N commented 9 months ago

Tak beru zpet, ted jsem si vsiml, ze mam rozdilne velikosti souboru, takze zrejme starsi verzi projektu. Po prepsani je uz vse ok.