ha-gismeteo
ha-gismeteo copied to clipboard
Yesterday weather
Environment
- Home Assistant Core release with the issue: 2021-6-0
- This custom component release with the issue: 2.3.3
- Last working this custom component release (if known): 2.3.3
- Operating environment (Home Assistant/Supervisor/Docker/venv): Supervisor
Describe the bug
The component returns to HA yesterday among forecast days.
Looks in UI
Now Thursday and 6/3 but not 6/2
Gismeteo API respond for https://services.gismeteo.ru/inform-service/inf_chrome/forecast/?city=229845&lang=en
Configuration.yaml
- name: gismeteo
platform: gismeteo
mode: daily
- name: gismeteo_h
platform: gismeteo
mode: hourly
Steps to Reproduce
Expected behavior Before 6/1 (apx) the component returned correct dates today, tomorrow...
Debug log
There're no any errors in logs
2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Data retrieved from https://services.gismeteo.ru/inform-service/inf_chrome/cities/?lat=54.1941381&lng=37.6877873&count=1&lang=en, status: 200 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.cache] Store cache file /config/.storage/location_54.1941381_37.6877873.xml 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Requesting URL https://services.gismeteo.ru/inform-service/inf_chrome/forecast/?city=229845&lang=en 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Cached response used 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.cache] Read cache file /config/.storage/forecast_229845.xml 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo] Finished fetching gismeteo data in 0.067 seconds 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Place coordinates: 54.1941381, 37.6877873 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Forecast mode: hourly 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.cache] Initializing cache 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Requesting URL https://services.gismeteo.ru/inform-service/inf_chrome/cities/?lat=54.1941381&lng=37.6877873&count=1&lang=en 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Cached response used 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.cache] Read cache file /config/.storage/location_54.1941381_37.6877873.xml 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Requesting URL https://services.gismeteo.ru/inform-service/inf_chrome/forecast/?city=229845&lang=en 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.api] Cached response used 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo.cache] Read cache file /config/.storage/forecast_229845.xml 2021-06-03 20:32:30 DEBUG (MainThread) [custom_components.gismeteo] Finished fetching gismeteo data in 0.089 seconds
I think there is some error in datetime conversion. Look, Gismeteo returns datetime in local timezone for selected place (UTC+6 in my case):
<day date="2021-06-07" risem="270" setm="1300" durm="1030" sunrise="1623040200" sunset="1623102000" tmin="12" tmax="26" pmin="748" pmax="753" wsmin="1" wsmax="2" hummin="22" hummax="60" cl="0" pt="0" pr="0" ts="0" icon="d" descr="Fair" p="750" ws="2" wd="6" hum="41" grademax="2" prflt="0" gust_speed="7">
<forecast valid="2021-06-07T00:00:00" tod="-1">
<values t="16" p="753" ws="1" wd="6" hum="44" hi="16" cl="0" pt="0" pr="0" prflt="0" ts="0" icon="n" descr="Fair" grade="1"/>
</forecast>
<forecast valid="2021-06-07T03:00:00" tod="0">
<values t="12" p="752" ws="1" wd="6" hum="59" hi="12" cl="0" pt="0" pr="0" prflt="0" ts="0" icon="n" descr="Fair" grade="1"/>
</forecast>
And, after some coversions forth and back (related to UTC. I think) ,this becames to Daily:
forecast:
- datetime: '2021-06-06T18:00:00+06:00'
condition: sunny
temperature: 26
And hourly:
forecast:
- datetime: '2021-06-06T21:00:00+06:00'
condition: clear-night
temperature: 12
do you see? now UTC time shown, but with TZ info added, which makes this lime local (look here for datetime formats: https://www.w3.org/TR/NOTE-datetime ). Therefore 6 hours time shift injected.
BTW, I think bug is somewhere in homeassistant.util.dt. I made a quick workaround in api.py:
tz_h, tz_m = divmod(abs(tzone), 60)
""" local_date += f"+{tz_h:02}:{tz_m:02}" if tzone >= 0 else f"-{tz_h:02}:{tz_m:02}" """
local_date += "Z"
return dt_util.as_timestamp(local_date)
It's completely wrong. But it's works :) Now datetime shown correctly.
The problem still in 2.4.0-beta1. I think it's because of double datetime conversion
in async_update(self)
and next in forecast(self, src=None)
.
Suggested changes
diff -urb gismeteo/api.py gismeteo.timefix/api.py
--- gismeteo/api.py 2022-01-07 05:25:24.256879150 +0600
+++ gismeteo.timefix/api.py 2022-01-07 17:20:37.774096020 +0600
@@ -140,11 +140,6 @@
self._last_updated = None
self._current = {}
self._forecast = []
- self._timezone = (
- dt_util.get_time_zone(params.get("timezone"))
- if params.get("timezone") is not None
- else dt_util.DEFAULT_TIME_ZONE
- )
@staticmethod
def _valid_coordinates(latitude: float, longitude: float) -> bool:
@@ -370,16 +365,13 @@
src = src or self._forecast
forecast = []
now = int(time.time())
- dt_util.set_default_time_zone(self._timezone)
for i in src:
fc_time = i.get(ATTR_FORECAST_TIME)
if fc_time is None:
continue
data = {
- ATTR_FORECAST_TIME: dt_util.as_local(
- datetime.utcfromtimestamp(fc_time)
- ).isoformat(),
+ ATTR_FORECAST_TIME: datetime.fromtimestamp(fc_time).isoformat(),
ATTR_FORECAST_CONDITION: self.condition(i),
ATTR_FORECAST_TEMP: self.temperature(i),
ATTR_FORECAST_PRESSURE: self.pressure_hpa(i),
same problem - gismeteo 2.3.4, HA core 2021.11.5
good afternoon ! there is a bug in mode: daily lag in the display for a day.
release 2.3.4, and 2.4.0b HA 2022.5.5
Same issue with HA 2022.5.5 and gismeteo 2.3.4 and 2.4.0-beta
Proposed changes from https://github.com/Limych/ha-gismeteo/issues/60#issuecomment-1007339489 fixed the issue for me.
так как исправлять эту ошибку?
так как исправлять эту ошибку?
Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...
так как исправлять эту ошибку?
Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...
Если бы еще знал какой код. Единственное понял, что в api.py
Если бы еще знал какой код. Единственное понял, что в api.py
Ну тут других вариантов нет. Либо вы знаете что такое diff, как его понимать, где искать api.py и как его править. Либо ждете пока автор не исправит в основном коде.
Ну тут других вариантов нет. Либо вы знаете что такое diff, как его понимать, где искать api.py и как его править. Либо ждете пока автор не исправит в основном коде.
Хорошо. Тупо вставить кусок кода сообщения в конце файла api.ry?
так как исправлять эту ошибку?
Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...
А кто-нибудь делал PR с этим фиксом за эти 2 года? Собираюсь у себя поправить, мне не сложно и PR кинуть, но что-то мне подсказывает, что раз за 2года этого никто не влил к автору 2 строчки кода со своего форка, то есть некоторые подводные камни.