Skip to content

Commit a618f23

Browse files
Khole JonesKhole Jones
authored andcommitted
Add parent device to new devicelist
1 parent 7609e05 commit a618f23

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.34.0
3+
rev: v3.20.0
44
hooks:
55
- id: pyupgrade
66
args: [--py38-plus]
77
- repo: https://github.com/psf/black
8-
rev: 22.3.0
8+
rev: 25.9.0
99
hooks:
1010
- id: black
1111
args:
1212
- --safe
1313
- --quiet
1414
- repo: https://github.com/codespell-project/codespell
15-
rev: v2.1.0
15+
rev: v2.4.1
1616
hooks:
1717
- id: codespell
1818
args:
@@ -21,36 +21,36 @@ repos:
2121
- --quiet-level=2
2222
exclude_types: [csv, json]
2323
- repo: https://github.com/pycqa/flake8
24-
rev: 3.9.2
24+
rev: 7.3.0
2525
hooks:
2626
- id: flake8
2727
additional_dependencies:
2828
- flake8-docstrings==1.5.0
2929
- pydocstyle==5.1.1
3030
- repo: https://github.com/PyCQA/bandit
31-
rev: 1.7.4
31+
rev: 1.8.6
3232
hooks:
3333
- id: bandit
3434
args:
3535
- --quiet
3636
- --format=custom
3737
- --configfile=tests/bandit.yaml
3838
- repo: https://github.com/PyCQA/isort
39-
rev: 5.12.0
39+
rev: 6.0.1
4040
hooks:
4141
- id: isort
4242
args: ["--profile", "black"]
4343
- repo: https://github.com/adrienverge/yamllint.git
44-
rev: v1.26.3
44+
rev: v1.37.1
4545
hooks:
4646
- id: yamllint
4747
- repo: https://github.com/pre-commit/mirrors-prettier
48-
rev: v2.7.1
48+
rev: v4.0.0-alpha.8
4949
hooks:
5050
- id: prettier
5151
stages: [manual]
5252
- repo: https://github.com/pre-commit/pre-commit-hooks
53-
rev: v4.3.0
53+
rev: v6.0.0
5454
hooks:
5555
- id: check-executables-have-shebangs
5656
stages: [manual]
@@ -59,13 +59,10 @@ repos:
5959
- id: no-commit-to-branch
6060
args:
6161
- --branch=master
62-
- repo: local
62+
- repo: https://github.com/pycqa/pylint
63+
rev: v3.3.1
6364
hooks:
6465
- id: pylint
65-
name: pylint
66-
entry: pylint
67-
language: system
68-
types: [python]
6966
args:
7067
[
7168
"-rn", # Only display messages

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99

1010
def requirements_from_file(filename="requirements_all.txt"):
1111
"""Get requirements from file."""
12-
with open(os.path.join(os.path.dirname(__file__), filename)) as r:
12+
with open(os.path.join(os.path.dirname(__file__), filename), encoding="utf-8") as r:
1313
reqs = r.read().strip().split("\n")
1414
# Return non empty lines and non comments
1515
return [r for r in reqs if re.match(r"^\w+", r)]
1616

1717

1818
setup(
19-
version="1.0.1",
19+
version="1.0.4",
2020
package_data={"data": ["*.json"]},
2121
include_package_data=True,
2222
cmdclass={
2323
"build_py": unasync.cmdclass_build_py(
2424
rules=[
2525
unasync.Rule(
2626
"/src/apyhiveapi/",
27-
"
28-
/pyhiveapi/",
27+
"/pyhiveapi/",
2928
additional_replacements={
3029
"apyhiveapi": "pyhiveapi",
3130
"asyncio": "threading",

src/apyhiveapi/api/hive_auth_async.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from ..helper.hive_exceptions import (
1919
HiveApiError,
20+
HiveFailedToRefreshTokens,
2021
HiveInvalid2FACode,
2122
HiveInvalidDeviceAuthentication,
2223
HiveInvalidPassword,
@@ -560,6 +561,12 @@ async def refresh_token(self, token):
560561
"NotAuthorizedException",
561562
"CodeMismatchException",
562563
):
564+
error_message = err.response.get("Error", {}).get("Message", "")
565+
if any(
566+
msg in error_message
567+
for msg in ["Refresh Token has expired", "Invalid Refresh Token"]
568+
):
569+
raise HiveFailedToRefreshTokens from err
563570
raise HiveInvalid2FACode from err
564571
except botocore.exceptions.EndpointConnectionError as err:
565572
if err.__class__.__name__ == "EndpointConnectionError":

src/apyhiveapi/session.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22

33
import asyncio
44
import copy
5-
from datetime import datetime, timedelta
65
import json
76
import operator
87
import os
98
import time
9+
from datetime import datetime, timedelta
1010
from typing import Optional
1111

1212
from aiohttp.web import HTTPException
1313

14-
15-
if __name__ == "pyhiveapi":
16-
from .api.hive_api import HiveApi as API
17-
from .api.hive_auth import HiveAuth as Auth
18-
else:
19-
from .api.hive_async_api import HiveApiAsync as API
20-
from .api.hive_auth_async import HiveAuthAsync as Auth
21-
2214
from .device_attributes import HiveAttributes
2315
from .helper.const import ACTIONS, DEVICES, HIVE_TYPES, PRODUCTS
2416
from .helper.hive_exceptions import (
@@ -36,6 +28,13 @@
3628
from .helper.logger import Logger
3729
from .helper.map import Map
3830

31+
if __name__ == "pyhiveapi":
32+
from .api.hive_api import HiveApi as API
33+
from .api.hive_auth import HiveAuth as Auth
34+
else:
35+
from .api.hive_async_api import HiveApiAsync as API
36+
from .api.hive_auth_async import HiveAuthAsync as Auth
37+
3938

4039
class HiveSession:
4140
"""Hive Session Code.
@@ -160,12 +159,18 @@ def add_list(self, entity_type: str, data: dict, **kwargs: dict):
160159
if kwargs.get("ha_name", "FALSE")[0] == " ":
161160
kwargs["ha_name"] = device_name + kwargs["ha_name"]
162161
else:
163-
formatted_data["ha_name"] = device_name
162+
formatted_data["haName"] = device_name
163+
164164
formatted_data.update(kwargs)
165-
self.device_list[entity_type].append(formatted_data)
165+
166+
if data.get("type", "") == "hub":
167+
self.device_list["parent"].append(formatted_data)
168+
else:
169+
self.device_list[entity_type].append(formatted_data)
170+
166171
return formatted_data
167172
except KeyError as error:
168-
self.logger.error(error)
173+
self.log.error(error)
169174
return None
170175

171176
async def update_interval(self, new_interval: timedelta):
@@ -488,7 +493,7 @@ async def start_session(self, config: dict = None):
488493
config (dict, optional): Configuration for Home Assistant to use. Defaults to {}.
489494
490495
Raises:
491-
HiveUnknownConfiguration: Unknown configuration identifed.
496+
HiveUnknownConfiguration: Unknown configuration identified.
492497
HiveReauthRequired: Tokens have expired and reauthentication is required.
493498
494499
Returns:
@@ -527,6 +532,7 @@ async def create_devices(self):
527532
Returns:
528533
list: List of devices
529534
"""
535+
self.device_list["parent"] = []
530536
self.device_list["alarm_control_panel"] = []
531537
self.device_list["binary_sensor"] = []
532538
self.device_list["camera"] = []
@@ -553,8 +559,7 @@ async def create_devices(self):
553559
try:
554560
eval("self." + code)
555561
except (NameError, AttributeError, KeyError) as e:
556-
self.logger.warning(f"Device {product_name} cannot be setup - {e}")
557-
pass
562+
self.log.warning(f"Device {product_name} cannot be setup - {e}")
558563

559564
if self.data.products[a_product]["type"] in hive_type:
560565
self.config.mode.append(p["id"])

0 commit comments

Comments
 (0)