Skip to content

Commit 9697023

Browse files
committed
Update pre-commit and run it
1 parent f70aba6 commit 9697023

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

pyhilo/api.py

100755100644
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from datetime import datetime, timedelta
54
import json
65
import random
76
import string
87
import sys
8+
from datetime import datetime, timedelta
99
from typing import Any, Callable, Union, cast
1010
from urllib import parse
1111

12+
import backoff
1213
from aiohttp import ClientSession
1314
from aiohttp.client_exceptions import ClientResponseError
14-
import backoff
1515
from homeassistant.helpers import config_entry_oauth2_flow
1616

1717
from pyhilo.const import (
@@ -129,10 +129,8 @@ def headers(self) -> dict[str, Any]:
129129
}
130130
return {
131131
**headers,
132-
**{
133-
"Content-Type": "application/json; charset=utf-8",
134-
"Ocp-Apim-Subscription-Key": SUBSCRIPTION_KEY,
135-
},
132+
"Content-Type": "application/json; charset=utf-8",
133+
"Ocp-Apim-Subscription-Key": SUBSCRIPTION_KEY,
136134
}
137135

138136
async def async_get_access_token(self) -> str:
@@ -516,7 +514,7 @@ async def _set_device_attribute(
516514
self,
517515
device: HiloDevice,
518516
key: DeviceAttribute,
519-
value: Union[str, float, int, None],
517+
value: Union[str, float, None],
520518
) -> None:
521519
url = self._get_url(f"Devices/{device.id}/Attributes", device.location_id)
522520
LOG.debug(f"Device Attribute URL is {url}")
@@ -545,7 +543,8 @@ async def get_event_notifications(self, location_id: int) -> dict[str, Any]:
545543
"homePageNotificationBody": "Test manuel de l’alarme détecté.",
546544
"notificationDataJSON": "{\"NotificationType\":null,\"Title\":\"\",\"SubTitle\":null,\"Body\":\"Test manuel de l’alarme détecté.\",\"Badge\":0,\"Sound\":null,\"Data\":null,\"Tags\":null,\"Type\":\"TestDetected\",\"DeviceId\":324236,\"LocationId\":4051}",
547545
"viewed": false
548-
}"""
546+
}
547+
"""
549548
url = self._get_url(None, location_id, events=True)
550549
LOG.debug(f"Event Notifications URL is {url}")
551550
return cast(dict[str, Any], await self.async_request("get", url))
@@ -613,7 +612,6 @@ async def get_gd_events(
613612
}
614613
}
615614
"""
616-
617615
url = self._get_url("Events", location_id, True)
618616
if not event_id:
619617
url += "?active=true"

pyhilo/const.py

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ANDROID_PKG_NAME: Final = "com.hiloenergie.hilo"
1616
DOMAIN: Final = "hilo"
1717
# Auth constants
18-
AUTH_HOSTNAME: Final = "connexion.hiloenergie.com"
18+
AUTH_HOSTNAME: Final = "connexion.hiloenergie.com" # codespell:ignore
1919
AUTH_ENDPOINT: Final = "/HiloDirectoryB2C.onmicrosoft.com/B2C_1A_SIGN_IN/oauth2/v2.0/"
2020
AUTH_AUTHORIZE: Final = f"https://{AUTH_HOSTNAME}{AUTH_ENDPOINT}authorize"
2121
AUTH_TOKEN: Final = f"https://{AUTH_HOSTNAME}{AUTH_ENDPOINT}token"

pyhilo/event.py

100755100644
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
"""Event object """
2-
from datetime import datetime, timedelta, timezone
1+
"""Event object"""
2+
33
import logging
44
import re
5+
from datetime import datetime, timedelta, timezone
56
from typing import Any, cast
67

78
from pyhilo.util import camel_to_snake, from_utc_timestamp
@@ -72,7 +73,8 @@ def update_wh(self, used_wH: float) -> None:
7273

7374
def should_check_for_allowed_wh(self) -> bool:
7475
"""This function is used to authorize subscribing to a specific event in Hilo to receive the allowed_kWh
75-
that is made available in the pre_heat phase"""
76+
that is made available in the pre_heat phase
77+
"""
7678
now = datetime.now(self.preheat_start.tzinfo)
7779
time_since_preheat_start = (self.preheat_start - now).total_seconds()
7880
already_has_allowed_wh = self.allowed_kWh > 0
@@ -150,25 +152,24 @@ def state(self) -> str:
150152
now = datetime.now(self.preheat_start.tzinfo)
151153
if self.pre_cold_start and self.pre_cold_start <= now < self.pre_cold_end:
152154
return "pre_cold"
153-
elif (
155+
if (
154156
self.appreciation_start
155157
and self.appreciation_start <= now < self.appreciation_end
156158
):
157159
return "appreciation"
158-
elif self.preheat_start > now:
160+
if self.preheat_start > now:
159161
return "scheduled"
160-
elif self.preheat_start <= now < self.preheat_end:
162+
if self.preheat_start <= now < self.preheat_end:
161163
return "pre_heat"
162-
elif self.reduction_start <= now < self.reduction_end:
164+
if self.reduction_start <= now < self.reduction_end:
163165
return "reduction"
164-
elif self.recovery_start <= now < self.recovery_end:
166+
if self.recovery_start <= now < self.recovery_end:
165167
return "recovery"
166-
elif now >= self.recovery_end + timedelta(minutes=5):
168+
if now >= self.recovery_end + timedelta(minutes=5):
167169
return "off"
168-
elif now >= self.recovery_end:
170+
if now >= self.recovery_end:
169171
return "completed"
170-
elif self.progress:
172+
if self.progress:
171173
return self.progress
172174

173-
else:
174-
return "unknown"
175+
return "unknown"

pyhilo/util/__init__.py

100755100644
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Define utility modules."""
2+
23
import asyncio
3-
from datetime import datetime, timedelta
44
import re
5+
from datetime import datetime, timedelta
56
from typing import Any, Callable
67

78
from dateutil import tz

pyhilo/websocket.py

100755100644
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Define a connection to the Hilo websocket."""
2+
23
from __future__ import annotations
34

45
import asyncio
6+
import json
57
from dataclasses import dataclass, field
68
from datetime import datetime, timedelta
79
from enum import IntEnum
8-
import json
910
from os import environ
1011
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Tuple
1112
from urllib import parse
@@ -338,10 +339,8 @@ async def async_listen(self) -> None:
338339
except ConnectionClosedError as err:
339340
LOG.error(f"Websocket: Closed while listening: {err}")
340341
LOG.exception(err)
341-
pass
342342
except InvalidMessageError as err:
343343
LOG.warning(f"Websocket: Received invalid json : {err}")
344-
pass
345344
finally:
346345
LOG.info("Websocket: Listen completed; cleaning up")
347346
self._watchdog.cancel()
@@ -420,6 +419,7 @@ def __init__(
420419
async_request: The async request method from the API class
421420
state_yaml: Path to the state file
422421
set_state_callback: Callback to save state
422+
423423
"""
424424
self.session = session
425425
self.async_request = async_request
@@ -445,8 +445,10 @@ async def refresh_token(
445445
self, config: WebsocketConfig, get_new_token: bool = True
446446
) -> None:
447447
"""Refresh token for a specific websocket configuration.
448+
448449
Args:
449450
config: The websocket configuration to refresh
451+
450452
"""
451453
if get_new_token:
452454
config.url, self._shared_token = await self._negotiate(config)
@@ -459,10 +461,12 @@ async def refresh_token(
459461

460462
async def _negotiate(self, config: WebsocketConfig) -> Tuple[str, str]:
461463
"""Negotiate websocket connection and get URL and token.
464+
462465
Args:
463466
config: The websocket configuration to negotiate
464467
Returns:
465468
Tuple containing the websocket URL and access token
469+
466470
"""
467471
LOG.debug(f"Getting websocket url for {config.endpoint}")
468472
url = f"{config.endpoint}/negotiate"
@@ -494,6 +498,7 @@ async def _get_websocket_params(self, config: WebsocketConfig) -> None:
494498
495499
Args:
496500
config: The websocket configuration to get parameters for
501+
497502
"""
498503
uri = parse.urlparse(config.url)
499504
LOG.debug(f"Getting websocket params for {config.endpoint}")

0 commit comments

Comments
 (0)