Skip to content

Commit

Permalink
Merge pull request #16 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
Fix retrieving dataa
  • Loading branch information
PiotrMachowski authored Jan 10, 2025
2 parents 82dd7ef + 3acbd56 commit 1ad007c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ on:
release:
types: [published]

env:
COMPONENT_NAME: hydro_imgw

jobs:
release:
name: Prepare release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Download repo
uses: actions/checkout@v1
uses: actions/checkout@v4.2.2

- name: Adjust version number
shell: bash
run: |
version="${{ github.event.release.tag_name }}"
yq e -P -o=json \
-i ".version = \"${version}\"" \
"${{ github.workspace }}/custom_components/${{ env.COMPONENT_NAME }}/manifest.json"
- name: Zip hydro_imgw dir
- name: Zip ${{ env.COMPONENT_NAME }} dir
run: |
cd /home/runner/work/Home-Assistant-custom-components-Hydro-IMGW/Home-Assistant-custom-components-Hydro-IMGW/custom_components/hydro_imgw
zip hydro_imgw.zip -r ./
cd "${{ github.workspace }}/custom_components/${{ env.COMPONENT_NAME }}"
zip ${{ env.COMPONENT_NAME }}.zip -r ./
- name: Upload zip to release
uses: svenstaro/upload-release-action@v1-release
uses: softprops/action-gh-release@v2.1.0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: /home/runner/work/Home-Assistant-custom-components-Hydro-IMGW/Home-Assistant-custom-components-Hydro-IMGW/custom_components/hydro_imgw/hydro_imgw.zip
asset_name: hydro_imgw.zip
tag: ${{ github.ref }}
overwrite: true
files: ${{ github.workspace }}/custom_components/${{ env.COMPONENT_NAME }}/${{ env.COMPONENT_NAME }}.zip
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.7"
"version": "v0.0.0"
}
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 1ad007c

Please sign in to comment.