Skip to content

Commit 846ecfb

Browse files
committed
Fix pre-commit
1 parent cb576b9 commit 846ecfb

14 files changed

Lines changed: 74 additions & 56 deletions

.pre-commit-config.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ repos:
99
- --format=custom
1010
- --configfile=.bandit.yaml
1111
files: ^pyhilo/.+\.py$
12-
- repo: https://github.com/python/black
13-
rev: 22.12.0
12+
- repo: https://github.com/psf/black
13+
rev: 24.1.1
1414
hooks:
1515
- id: black
1616
args:
@@ -19,39 +19,37 @@ repos:
1919
language_version: python3
2020
files: ^((pyhilo|tests)/.+)?[^/]+\.py$
2121
- repo: https://github.com/codespell-project/codespell
22-
rev: v1.16.0
22+
rev: v2.2.6
2323
hooks:
2424
- id: codespell
2525
args:
2626
- --skip="./.*,*.json"
2727
- --quiet-level=4
28-
- -L ba,hass
28+
- -L ba,hass,manuel,connexion
2929
exclude_types: [json]
3030
- repo: https://github.com/PyCQA/flake8
31-
rev: 4.0.1
31+
rev: 7.0.0
3232
hooks:
3333
- id: flake8
3434
additional_dependencies:
35-
- flake8-docstrings==1.5.0
36-
- pydocstyle==5.0.1
35+
- flake8-docstrings==1.7.0
36+
- pydocstyle==6.3.0
3737
files: ^pyhilo/.+\.py$
38-
- repo: https://github.com/pre-commit/mirrors-isort
39-
rev: v4.3.21
38+
- repo: https://github.com/pycqa/isort
39+
rev: 5.13.2
4040
hooks:
4141
- id: isort
42-
additional_dependencies:
43-
- toml
4442
files: ^(pyhilo|tests)/.+\.py$
4543
- repo: https://github.com/pre-commit/mirrors-mypy
46-
rev: v1.18.2
44+
rev: v1.8.0
4745
hooks:
4846
- id: mypy
4947
files: ^pyhilo/.+\.py$
5048
additional_dependencies:
5149
- types-python-dateutil==2.8.0
5250
- types-aiofiles==23.2.0
5351
- types-PyYAML
54-
52+
5553
- repo: https://github.com/pre-commit/pre-commit-hooks
5654
rev: v5.0.0
5755
hooks:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

doc/Readme.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
# Using get_tokens.py
2+
23
This python script will let you use it to log in to your Hilo account.
34

45
From there, you will be asked to copy the full HA redirect(callback) URL and go back to your python script and press enter.
56

67
Negotiation will take place and you will receive three distinct tokens:
8+
79
- Your access token
810
- Your devicehub token
911
- Your challengehub token
1012

1113
Take care not to share your tokens as they are not encrypted and contain personally identifiable information.
1214

1315
1. Run get_tokens.py, you will be provided with a link. Either click it or copy it in your favourite browser.
14-
<img width="1393" height="186" alt="image" src="https://github.com/user-attachments/assets/0b9559b1-1d9a-41ae-b4bf-185a5a5c588b" />
16+
<img width="1393" height="186" alt="image" src="https://github.com/user-attachments/assets/0b9559b1-1d9a-41ae-b4bf-185a5a5c588b" />
1517

1618
2. Login using your Hilo Credentials
17-
19+
1820
<img width="631" height="569" alt="image" src="https://github.com/user-attachments/assets/ad7c79a7-2402-44e8-9a0b-962406b89527" />
1921

2022
3. Once you get to this page, select the URL and copy it to clipboard
21-
<img width="694" height="274" alt="image" src="https://github.com/user-attachments/assets/85989069-31a3-418d-b305-1f2378432d84" />
22-
<img width="567" height="46" alt="image" src="https://github.com/user-attachments/assets/1d979626-6d93-46cb-aae0-50ef061a0d61" />
23+
<img width="694" height="274" alt="image" src="https://github.com/user-attachments/assets/85989069-31a3-418d-b305-1f2378432d84" />
24+
<img width="567" height="46" alt="image" src="https://github.com/user-attachments/assets/1d979626-6d93-46cb-aae0-50ef061a0d61" />
2325

2426
4. Go back to get_tokens.py and press enter, you'll get all 3 tokens:
2527

2628
<img width="1208" height="805" alt="image" src="https://github.com/user-attachments/assets/10258890-e935-4b16-8d16-12bdd340c001" />
27-
2829

2930
# Using Postman to send payloads to devicehub or challengehub
31+
3032
## Prerequisite: you need to have your tokens on hand, they are relatively short lived so once you have them, get to connecting!
3133

3234
### DeviceHub
@@ -43,7 +45,9 @@ Take care not to share your tokens as they are not encrypted and contain persona
4345
"version": 1
4446
}
4547
```
46-
5. You can then invoke "SubscribeToLocation" to get your device informations.
48+
49+
5. You can then invoke "SubscribeToLocation" to get your device information.
50+
4751
```
4852
{
4953
"arguments": [
@@ -54,6 +58,7 @@ Take care not to share your tokens as they are not encrypted and contain persona
5458
"type": 1
5559
}
5660
```
61+
5762
6. You should received the DeviceListInitialValuesReceived message back.
5863

5964
### ChallengeHub
@@ -70,20 +75,21 @@ Take care not to share your tokens as they are not encrypted and contain persona
7075
"version": 1
7176
}
7277
```
73-
5. You can send various messages to the ChallengeHub to request different information. For the 2025-2026 season with the addition of Flex D, the messages were split between Winter Credit (Crédit Hivernal) and Flex D. Winter Credit messages will contain CH in their target, and Flex D event will contain Flex in their target. Each of rates has its own event id, for example, event 337 was for Winter Credits, and event 338 was for Flex D, both occured at the same time. You will have access to one, or the other, depending on your rate.
7478

79+
5. You can send various messages to the ChallengeHub to request different information. For the 2025-2026 season with the addition of Flex D, the messages were split between Winter Credit (Crédit Hivernal) and Flex D. Winter Credit messages will contain CH in their target, and Flex D event will contain Flex in their target. Each of rates has its own event id, for example, event 337 was for Winter Credits, and event 338 was for Flex D, both occurred at the same time. You will have access to one, or the other, depending on your rate.
7580

7681
### Examples of various invokesto the ChallengeHub
7782

7883
#### SubscribeToEventCH or SubscribeToEventFlex
7984

8085
This invoke is used:
86+
8187
```
8288
{
8389
"arguments": [
8490
{
8591
"locationHiloId": "urn:YOUR-URN",
86-
"eventId": ID(numberic)
92+
"eventId": ID(numeric)
8793
}
8894
],
8995
"invocationId": "1",
@@ -93,13 +99,13 @@ This invoke is used:
9399
```
94100

95101
And should return
102+
96103
```
97104
EventCHDetailsInitialValuesReceived
98-
````
99-
Or
100-
```
101-
EventFlexDetailsInitialValuesReceived
102105
```
103106

107+
Or
104108

105-
109+
```
110+
EventFlexDetailsInitialValuesReceived
111+
```

pyhilo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Define the hilo package."""
2+
23
from pyhilo.api import API
34
from pyhilo.const import UNMONITORED_DEVICES
45
from pyhilo.device import HiloDevice

pyhilo/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ def dev_atts(
193193
for x in self.device_attributes
194194
if x.hilo_attribute == attribute or x.attr == attribute
195195
),
196-
DeviceAttribute(attribute, HILO_READING_TYPES.get(value_type, "null"))
197-
if value_type
198-
else attribute,
196+
(
197+
DeviceAttribute(attribute, HILO_READING_TYPES.get(value_type, "null"))
198+
if value_type
199+
else attribute
200+
),
199201
)
200202

201203
async def _get_fid_state(self) -> bool:

pyhilo/const.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import platform
3-
import uuid
43
from typing import Final
4+
import uuid
55

66
import aiohttp
77

@@ -24,7 +24,9 @@
2424
AUTH_TOKEN: Final = f"https://{AUTH_HOSTNAME}{AUTH_ENDPOINT}token"
2525
AUTH_CHALLENGE_METHOD: Final = "S256"
2626
AUTH_CLIENT_ID: Final = "1ca9f585-4a55-4085-8e30-9746a65fa561"
27-
AUTH_SCOPE: Final = "openid https://HiloDirectoryB2C.onmicrosoft.com/hiloapis/user_impersonation offline_access"
27+
AUTH_SCOPE: Final = (
28+
"openid https://HiloDirectoryB2C.onmicrosoft.com/hiloapis/user_impersonation offline_access"
29+
)
2830
SUBSCRIPTION_KEY: Final = "20eeaedcb86945afa3fe792cea89b8bf"
2931

3032
# API constants
@@ -50,7 +52,9 @@
5052

5153

5254
# Request constants
53-
DEFAULT_USER_AGENT: Final = f"PyHilo/{PYHILO_VERSION}-{INSTANCE_ID} aiohttp/{aiohttp.__version__} Python/{platform.python_version()}"
55+
DEFAULT_USER_AGENT: Final = (
56+
f"PyHilo/{PYHILO_VERSION}-{INSTANCE_ID} aiohttp/{aiohttp.__version__} Python/{platform.python_version()}"
57+
)
5458

5559

5660
# NOTE(dvd): Not sure how to get new ones so I'm using the ones from my emulator

pyhilo/device/climate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Climate object."""
2+
23
from __future__ import annotations
34

45
from typing import Any, cast

pyhilo/device/graphql_value_mapper.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GraphqlValueMapper:
1111

1212
OnState = "on"
1313

14-
def map_query_values(self, values: Dict[str, Any]) -> list[Dict[str, Any]]:
14+
def map_query_values(self, values: list[Dict[str, Any]]) -> list[Dict[str, Any]]:
1515
readings: list[Dict[str, Any]] = []
1616
for device in values:
1717
if device.get("deviceType") is not None:
@@ -20,7 +20,7 @@ def map_query_values(self, values: Dict[str, Any]) -> list[Dict[str, Any]]:
2020
return readings
2121

2222
def map_device_subscription_values(
23-
self, device: list[Dict[str, Any]]
23+
self, device: Dict[str, Any]
2424
) -> list[Dict[str, Any]]:
2525
readings: list[Dict[str, Any]] = []
2626
if device.get("deviceType") is not None:
@@ -32,7 +32,7 @@ def map_location_subscription_values(
3232
self, values: Dict[str, Any]
3333
) -> list[Dict[str, Any]]:
3434
readings: list[Dict[str, Any]] = []
35-
for device in values:
35+
for device in values.get("devices", []):
3636
if device.get("deviceType") is not None:
3737
reading = self._map_devices_values(device)
3838
readings.extend(reading)
@@ -425,7 +425,8 @@ def _build_light(self, device: Dict[str, Any]) -> list[Dict[str, Any]]:
425425
device["hiloId"], "Intensity", device["level"] / 100
426426
)
427427
)
428-
if device.get("lightType").lower() == "color":
428+
light_type = device.get("lightType")
429+
if light_type and light_type.lower() == "color":
429430
attributes.append(
430431
self.build_attribute(device["hiloId"], "Hue", device.get("hue") or 0)
431432
)

pyhilo/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Event:
2727

2828
def __init__(self, **event: dict[str, Any]):
2929
"""Initialize."""
30-
self._convert_phases(cast(dict[str, Any], event.get("phases", {})))
30+
self._convert_phases(event.get("phases", {}))
3131
params: dict[str, Any] = event.get("parameters") or {}
3232
devices: list[dict[str, Any]] = params.get("devices", [])
3333
consumption: dict[str, Any] = event.get("consumption", {})

pyhilo/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Define package errors."""
2+
23
from __future__ import annotations
34

45

0 commit comments

Comments
 (0)