Skip to content

Commit

Permalink
Fix retrieving data
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMachowski committed Jan 10, 2025
1 parent 82dd7ef commit 37269f0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions custom_components/hydro_imgw/sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import timedelta
import logging
from datetime import timedelta

import homeassistant.helpers.config_validation as cv
import requests
import voluptuous as vol

from homeassistant.components.sensor import (PLATFORM_SCHEMA, ENTITY_ID_FORMAT, SensorEntity, SensorStateClass)
from homeassistant.const import CONF_NAME, UnitOfLength, ATTR_ATTRIBUTION
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.reload import async_setup_reload_service

Expand Down Expand Up @@ -88,7 +87,10 @@ def unit_of_measurement(self):
def update(self):
try:
address = f"https://hydro-back.imgw.pl/station/hydro/status?id={self._station_id}"
request = requests.get(address, timeout=240)
headers = {
"User-Agent": "Chrome/131.0.0.0"
}
request = requests.get(address, timeout=240, headers=headers)
if request.status_code == 200 and request.content.__len__() > 0:
self._data = request.json()
except:
Expand All @@ -102,6 +104,7 @@ def extractor_arr(json_obj, path_array):
if len(path_array) > 1:
return extractor_arr(json_obj[path_array[0]], path_array[1:])
return json_obj[path_array[0]]

try:
return extractor_arr(json, path.split("."))
except:
Expand Down

0 comments on commit 37269f0

Please sign in to comment.