From 8e30ac09e0fa74288ab67160f4b4c22b4829e8b8 Mon Sep 17 00:00:00 2001 From: Matt B Date: Fri, 22 Nov 2024 11:11:00 +0000 Subject: [PATCH 01/12] Update session.py This change prevents the integration from failing to load when there is a problem with one of the devices. Seems to be a common problem. --- pyhiveapi/apyhiveapi/session.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index 25ac508..0de84c5 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -536,7 +536,10 @@ async def createDevices(self): continue product_list = PRODUCTS.get(self.data.products[aProduct]["type"], []) for code in product_list: - eval("self." + code) + try: + eval("self." + code) + except: + pass if self.data.products[aProduct]["type"] in hive_type: self.config.mode.append(p["id"]) From 91a96f82f24e35a8a92245d887ca97d1dcbacdd1 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Tue, 7 Jan 2025 23:51:15 +0000 Subject: [PATCH 02/12] update catch for TRV --- pyhiveapi/apyhiveapi/helper/hive_helper.py | 18 +++++++++++------- pyhiveapi/apyhiveapi/session.py | 22 +++++++++++----------- setup.py | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pyhiveapi/apyhiveapi/helper/hive_helper.py b/pyhiveapi/apyhiveapi/helper/hive_helper.py index 2da30d0..9677088 100644 --- a/pyhiveapi/apyhiveapi/helper/hive_helper.py +++ b/pyhiveapi/apyhiveapi/helper/hive_helper.py @@ -81,7 +81,7 @@ def getDeviceData(self, product: dict): Returns: [type]: Device data. """ - device = product + device_id = product["id"] type = product["type"] if type in ("heating", "hotwater"): for aDevice in self.session.data.devices: @@ -91,19 +91,23 @@ def getDeviceData(self, product: dict): product["props"]["zone"] == self.session.data.devices[aDevice]["props"]["zone"] ): - device = self.session.data.devices[aDevice] + device_id = self.session.data.devices[aDevice]["id"] except KeyError: pass elif type == "trvcontrol": - device = self.session.data.devices[product["props"]["trvs"][0]] + trv_present = len(product["props"]["trvs"]) > 0 + if trv_present: + device_id = self.session.data.devices[product["props"]["trvs"][0]]["id"] + else: + raise KeyError elif type == "warmwhitelight" and product["props"]["model"] == "SIREN001": - device = self.session.data.devices[product["parent"]] + device_id = self.session.data.devices[product["parent"]] elif type == "sense": - device = self.session.data.devices[product["parent"]] + device_id = self.session.data.devices[product["parent"]] else: - device = self.session.data.devices[product["id"]] + device_id = self.session.data.devices[product["id"]] - return device + return device_id def convertMinutesToTime(self, minutes_to_convert: str): """Convert minutes string to datetime. diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index 25ac508..75e1256 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -128,15 +128,15 @@ def addList(self, entityType: str, data: dict, **kwargs: dict): Returns: dict: Entity. """ - device = self.helper.getDeviceData(data) - device_name = ( - device["state"]["name"] - if device["state"]["name"] != "Receiver" - else "Heating" - ) - formatted_data = {} - try: + device = self.helper.getDeviceData(data) + device_name = ( + device["state"]["name"] + if device["state"]["name"] != "Receiver" + else "Heating" + ) + formatted_data = {} + formatted_data = { "hiveID": data.get("id", ""), "hiveName": device_name, @@ -154,11 +154,11 @@ def addList(self, entityType: str, data: dict, **kwargs: dict): else: formatted_data["haName"] = device_name formatted_data.update(kwargs) + self.deviceList[entityType].append(formatted_data) + return formatted_data except KeyError as error: self.logger.error(error) - - self.deviceList[entityType].append(formatted_data) - return formatted_data + return None async def updateInterval(self, new_interval: timedelta): """Update the scan interval. diff --git a/setup.py b/setup.py index e3a4769..98df848 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def requirements_from_file(filename="requirements.txt"): setup( - version="0.5.16", + version="0.5.17", package_data={"data": ["*.json"]}, include_package_data=True, cmdclass={ From dd0c9546571a3ec0f06f83d6813dfb25e84e3e7c Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Wed, 8 Jan 2025 00:03:35 +0000 Subject: [PATCH 03/12] fix liniting issue with exception --- pyhiveapi/apyhiveapi/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index f1ce3e3..d0dde40 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -535,10 +535,12 @@ async def createDevices(self): ): continue product_list = PRODUCTS.get(self.data.products[aProduct]["type"], []) + product_name = self.data.products[aProduct]["state"].get("name", "Unknown") for code in product_list: try: eval("self." + code) - except: + except (NameError, AttributeError) as e: + self.log.warning(f"Device {product_name} cannot be setup - {e}") pass if self.data.products[aProduct]["type"] in hive_type: From ae1760b56fc1f6d4d64f574d99513390b053932e Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:09:41 +0000 Subject: [PATCH 04/12] update workflows --- .github/workflows/codeql-analysis.yml | 34 --------------------------- .github/workflows/python-package.yml | 2 +- .github/workflows/python-publish.yml | 27 --------------------- 3 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 73d0f9f..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [master] - pull_request: - # The branches below must be a subset of the branches above - branches: [master] - schedule: - - cron: "37 8 * * 3" - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-20.04 - - strategy: - fail-fast: false - matrix: - language: ["python"] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b8e9aed..e7771da 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 3303874..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Upload Python Package - -on: - release: - types: [published] - -jobs: - deploy: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine unasync - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* From 374bfe64f1ca9ca8ef035b8c2b3eeb3152722f47 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:11:45 +0000 Subject: [PATCH 05/12] add publish in --- .github/workflows/python-publish.yml | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..82f8dbd --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,70 @@ +# This workflow will upload a Python Package to PyPI when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + release-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Build release distributions + run: | + # NOTE: put your own distribution build steps here. + python -m pip install build + python -m build + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + pypi-publish: + runs-on: ubuntu-latest + needs: + - release-build + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + # Dedicated environments with protections for publishing are strongly recommended. + # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules + environment: + name: pypi + # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: + # url: https://pypi.org/p/YOURPROJECT + # + # ALTERNATIVE: if your GitHub Release name is the PyPI project version string + # ALTERNATIVE: exactly, uncomment the following line instead: + # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ From 0dc21d5f52ab7f45a06ce7722f55a5c1e982ac61 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:17:03 +0000 Subject: [PATCH 06/12] update config --- setup.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 27b27d3..c6316ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,10 @@ [metadata] -name = pyhiveapi +name = pyhive description = A Python library to interface with the Hive API keywords = Hive API Library license = MIT -author = Rendili -author_email = rendili@outlook.com +author = KJonline24 +author_email = khole_47@icloud.com url = https://github.com/Pyhive/pyhiveapi project_urls = Source = https://github.com/Pyhive/Pyhiveapi From f47a70bce7e93b460492b445fe82cb20ae9cfe10 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:25:22 +0000 Subject: [PATCH 07/12] update libary name --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index c6316ee..325cf5f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = pyhive +name = pyhive-integration description = A Python library to interface with the Hive API keywords = Hive API Library license = MIT From 96a5e1302eeb013635f8758b14d99fa173dd9229 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:47:13 +0000 Subject: [PATCH 08/12] update publish info --- .github/workflows/python-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 82f8dbd..e101b8f 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -51,7 +51,7 @@ jobs: environment: name: pypi # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: - # url: https://pypi.org/p/YOURPROJECT + url: https://pypi.org/project/pyhive-integration # # ALTERNATIVE: if your GitHub Release name is the PyPI project version string # ALTERNATIVE: exactly, uncomment the following line instead: From e2372ae803cfa541a9089f4b74eed2c601d790a0 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:52:20 +0000 Subject: [PATCH 09/12] V1.0.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 98df848..26341f7 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def requirements_from_file(filename="requirements.txt"): setup( - version="0.5.17", + version="1.0.0", package_data={"data": ["*.json"]}, include_package_data=True, cmdclass={ From 1d2484626b39e720b059056776aff3304aecdc2a Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 21:59:21 +0000 Subject: [PATCH 10/12] add python whl to github release --- .github/workflows/python-publish.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index e101b8f..472cd19 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -31,6 +31,13 @@ jobs: # NOTE: put your own distribution build steps here. python -m pip install build python -m build + + - name: Upload wheel to GitHub Release + uses: ncipollo/release-action@v1 + with: + artifacts: "dist/*.whl" # Path to your wheel file(s) + tag: ${{ github.ref_name }} + allowUpdates: true - name: Upload distributions uses: actions/upload-artifact@v4 From 181f4d91a2540cc6282f53437380bf792c6c0284 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 22:03:27 +0000 Subject: [PATCH 11/12] add write permission --- .github/workflows/python-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 472cd19..6c4382b 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,7 +13,7 @@ on: types: [published] permissions: - contents: read + contents: write jobs: release-build: From 6b9afd01dc29d04bdeced7972422329e9f91d554 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Sun, 12 Jan 2025 22:41:14 +0000 Subject: [PATCH 12/12] fix trv fix --- pyhiveapi/apyhiveapi/helper/hive_helper.py | 14 +++++++------- pyhiveapi/apyhiveapi/session.py | 2 +- setup.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyhiveapi/apyhiveapi/helper/hive_helper.py b/pyhiveapi/apyhiveapi/helper/hive_helper.py index 9677088..7943cd7 100644 --- a/pyhiveapi/apyhiveapi/helper/hive_helper.py +++ b/pyhiveapi/apyhiveapi/helper/hive_helper.py @@ -81,7 +81,7 @@ def getDeviceData(self, product: dict): Returns: [type]: Device data. """ - device_id = product["id"] + device = product type = product["type"] if type in ("heating", "hotwater"): for aDevice in self.session.data.devices: @@ -91,23 +91,23 @@ def getDeviceData(self, product: dict): product["props"]["zone"] == self.session.data.devices[aDevice]["props"]["zone"] ): - device_id = self.session.data.devices[aDevice]["id"] + device = self.session.data.devices[aDevice] except KeyError: pass elif type == "trvcontrol": trv_present = len(product["props"]["trvs"]) > 0 if trv_present: - device_id = self.session.data.devices[product["props"]["trvs"][0]]["id"] + device = self.session.data.devices[product["props"]["trvs"][0]] else: raise KeyError elif type == "warmwhitelight" and product["props"]["model"] == "SIREN001": - device_id = self.session.data.devices[product["parent"]] + device = self.session.data.devices[product["parent"]] elif type == "sense": - device_id = self.session.data.devices[product["parent"]] + device = self.session.data.devices[product["parent"]] else: - device_id = self.session.data.devices[product["id"]] + device = self.session.data.devices[product["id"]] - return device_id + return device def convertMinutesToTime(self, minutes_to_convert: str): """Convert minutes string to datetime. diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index d0dde40..4868a6b 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -540,7 +540,7 @@ async def createDevices(self): try: eval("self." + code) except (NameError, AttributeError) as e: - self.log.warning(f"Device {product_name} cannot be setup - {e}") + self.logger.warning(f"Device {product_name} cannot be setup - {e}") pass if self.data.products[aProduct]["type"] in hive_type: diff --git a/setup.py b/setup.py index 26341f7..b5c635c 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def requirements_from_file(filename="requirements.txt"): setup( - version="1.0.0", + version="1.0.1", package_data={"data": ["*.json"]}, include_package_data=True, cmdclass={