Skip to content

Commit

Permalink
Merge pull request #12 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
PiotrMachowski authored Mar 12, 2024
2 parents f11903f + 66156c1 commit d73679d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion custom_components/hydro_imgw/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Hydro-IMGW/issues",
"requirements": ["requests"],
"version": "v1.0.5"
"version": "v1.0.6"
}
25 changes: 12 additions & 13 deletions custom_components/hydro_imgw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,35 @@ def extra_state_attributes(self):
attr_paths = {
"current_date": "status.currentState.date",
"previous_date": "status.previousState.date",
"alarm_value": "alarmValue",
"warning_value": "warningValue",
"high_value": "highValue",
"low_value": "lowValue",
"trend": "trend",
"name": "name",
"level": "state",
"alarm_value": "status.alarmValue",
"warning_value": "status.warningValue",
"trend": "status.trend",
"name": "status.description",
"level": "stateCode",
"river": "status.river"
}
attributes = {}
for name, json_path in attr_paths.items():
attributes[name] = HydroImgwSensor.extractor(self._data, json_path)
attr_value = HydroImgwSensor.extractor(self._data, json_path)
if attr_value is not None:
attributes[name] = attr_value
return attributes

@property
def unit_of_measurement(self):
return UnitOfLength.CENTIMETERS

def update(self):
address = 'https://hydro.imgw.pl/api/station/hydro/?id={}'.format(self._station_id)
headers = {
"host": "hydro.imgw.pl"
}
request = requests.get(address, headers=headers)
address = f"https://hydro-back.imgw.pl/station/hydro/status?id={self._station_id}"
request = requests.get(address)
if request.status_code == 200 and request.content.__len__() > 0:
self._data = request.json()

@staticmethod
def extractor(json, path):
def extractor_arr(json_obj, path_array):
if path_array[0] not in json_obj:
return None
if len(path_array) > 1:
return extractor_arr(json_obj[path_array[0]], path_array[1:])
return json_obj[path_array[0]]
Expand Down

0 comments on commit d73679d

Please sign in to comment.