ha-gismeteo icon indicating copy to clipboard operation
ha-gismeteo copied to clipboard

Yesterday weather

Open dreem2001 opened this issue 3 years ago • 12 comments

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 image 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 image

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

dreem2001 avatar Jun 03 '21 17:06 dreem2001

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.

vegetate7 avatar Jun 06 '21 22:06 vegetate7

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.

vegetate7 avatar Jun 06 '21 23:06 vegetate7

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),

vegetate7 avatar Jan 07 '22 11:01 vegetate7

same problem - gismeteo 2.3.4, HA core 2021.11.5

alex-i-m avatar Jan 14 '22 14:01 alex-i-m

good afternoon ! there is a bug in mode: daily lag in the display for a day.

Screenshot_567

release 2.3.4, and 2.4.0b HA 2022.5.5

edw246 avatar May 24 '22 03:05 edw246

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.

anyuta1166 avatar May 25 '22 20:05 anyuta1166

так как исправлять эту ошибку?

mythosGH avatar Oct 11 '23 18:10 mythosGH

так как исправлять эту ошибку?

Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...

anyuta1166 avatar Oct 11 '23 18:10 anyuta1166

так как исправлять эту ошибку?

Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...

Если бы еще знал какой код. Единственное понял, что в api.py

mythosGH avatar Oct 11 '23 19:10 mythosGH

Если бы еще знал какой код. Единственное понял, что в api.py

Ну тут других вариантов нет. Либо вы знаете что такое diff, как его понимать, где искать api.py и как его править. Либо ждете пока автор не исправит в основном коде.

vegetate7 avatar Oct 11 '23 19:10 vegetate7

Ну тут других вариантов нет. Либо вы знаете что такое diff, как его понимать, где искать api.py и как его править. Либо ждете пока автор не исправит в основном коде.

Хорошо. Тупо вставить кусок кода сообщения в конце файла api.ry?

mythosGH avatar Oct 11 '23 19:10 mythosGH

так как исправлять эту ошибку?

Блин, ну написано же. Посмотрите чуть выше. Вручную правите код и все работает. Правки несколькими сообщениями ранее. Странно, что прошло почти 2 года, а автор так и не применил исправления...

А кто-нибудь делал PR с этим фиксом за эти 2 года? Собираюсь у себя поправить, мне не сложно и PR кинуть, но что-то мне подсказывает, что раз за 2года этого никто не влил к автору 2 строчки кода со своего форка, то есть некоторые подводные камни.

Red724 avatar Oct 13 '23 08:10 Red724