denysdovhan / ha-yasno-outages

⚡️ Yasno electricity outages (due to war in Ukraine) integration for Home Assistant.
MIT License
84 stars 10 forks source link

Data is not pulled from Yasno correctly #31

Open Fisarl opened 3 days ago

Fisarl commented 3 days ago

Hello @denysdovhan ,

First of all, thank you for this wonderful integration! However, since yesterday, I’ve noticed that the electricity outage plans have been updated on Yasno, but these updates are not reflected in your integration.

Data in HA: image

Data at Yasno: image

It seems that, for some reason, "possible outages" are still present in your integration, even though Yasno has removed them from their website.

denysdovhan commented 2 days ago

Hey, I am aware of this issue. Yasno now returns two types of schedule on their unofficial API: regular and daily schedule.

This change shouldn't be hard to make, but I don't have much time for that. I will try my best to make necessary changes as soon as possible.

asp24 commented 2 days ago

@denysdovhan it's looks same

curl https://api.yasno.com.ua/api/v1/pages/home/schedule-turn-off-electricity | jq '.components[] | select( .template_name == "electricity-outages-schedule" and ( .available_regions[] | contains("kiev"))) | .schedule.kiev.group_2'

and

curl https://api.yasno.com.ua/api/v1/pages/home/schedule-turn-off-electricity | jq '.components[] | select( .template_name == "electricity-outages-daily-schedule" and ( .available_regions[] | contains("kiev"))) | .schedule.kiev.group_2'

or you know other api?

Maxim-Inv commented 2 days ago

@asp24 Yes, dictionary electricity-outages-daily-schedule contains a new schedule of outage.

@denysdovhan I tried to implement it in my fork but wasn't able to test it before PR. I added my repo to HA instead yours (before removed it), but the integration didn't appear. Why it can be?

asp24 commented 2 days ago

@Maxim-Inv in this case it will not help. Data returned inside electricity-outages-daily-schedule differs from rendered on the page. Proper schedule rendered into HTML on the backend. The minimal request to recieve it looks like this curl -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' --cookie 'region=%7B%22id%22%3A44%2C%22name%22%3A%22%D0%9A%D0%B8%D1%97%D0%B2%22%2C%22key%22%3A%22kiev%22%2C%22subdomain%22%3A%22kyiv%22%7D' https://yasno.com.ua/schedule-turn-off-electricity

Nobody likes to parse HTML, but I did not find any XHR request returning "right" schedule

denysdovhan commented 2 days ago

You should look for dailySchedule property, not schedule.

asp24 commented 2 days ago

@denysdovhan Tnhx. I've missed this. Here is right filter for any who will be interested building other implementations

curl  https://api.yasno.com.ua/api/v1/pages/home/schedule-turn-off-electricity | jq '.components[] | select( .template_name == "electricity-outages-daily-schedule" and ( .available_regions[] | contains("kiev"))) | .dailySchedule.kiev.today.groups'
Maxim-Inv commented 1 day ago

You should look for dailySchedule property, not schedule.

My bad, forgot to say that new schedule called dailySchedule.

Almost ready, I just want to check it tomorrow. Unfortunately, I only get data for today, there will be need to process data for tomorrow.

P.S. I'm noob in Python, use ChatGPT and developer experience in other languages. :)