Skip to content

Commit d307315

Browse files
committed
Add more typing
1 parent 11da526 commit d307315

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

plugwise/helper.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
)
5252

5353

54-
def pw_notification_updater(devs, d_id, d_dict, notifs):
54+
def pw_notification_updater(devs, d_id, d_dict, notifs) -> None:
5555
"""Helper-function for async_update().
5656
Update the PW_Notification binary_sensor state.
5757
"""
@@ -83,7 +83,7 @@ def check_model(name, v_name) -> str:
8383
return name
8484

8585

86-
def schemas_schedule_temp(schedules, name) -> float:
86+
def schemas_schedule_temp(schedules, name) -> float | None:
8787
"""Helper-function for schemas().
8888
Obtain the schedule temperature of the schema/schedule.
8989
"""
@@ -95,8 +95,8 @@ def schemas_schedule_temp(schedules, name) -> float:
9595
tmp_list: list[tuple[str, str, float]] = []
9696
moment, dummy = period.split(",")
9797
moment = moment.replace("[", "").split(" ")
98-
day_nr = DAYS.get(moment[0], "None")
99-
start_time = dt.datetime.strptime(moment[1], "%H:%M").time()
98+
day_nr: str = DAYS.get(moment[0], "None")
99+
start_time: dt.datetime = dt.datetime.strptime(moment[1], "%H:%M").time()
100100
tmp_list.extend((day_nr, start_time, temp))
101101
schema_list.append(tmp_list)
102102

@@ -137,9 +137,9 @@ def types_finder(data):
137137
return types
138138

139139

140-
def power_data_local_format(attrs, key_string, val):
140+
def power_data_local_format(attrs, key_string, val) -> float | int:
141141
"""Format power data."""
142-
f_val = format_measure(val, attrs[ATTR_UNIT_OF_MEASUREMENT])
142+
f_val: float | int = format_measure(val, attrs[ATTR_UNIT_OF_MEASUREMENT])
143143
# Format only HOME_MEASUREMENT POWER_WATT values, do not move to util-format_meaure function!
144144
if attrs[ATTR_UNIT_OF_MEASUREMENT] == POWER_WATT:
145145
f_val = int(round(float(val)))
@@ -149,10 +149,12 @@ def power_data_local_format(attrs, key_string, val):
149149
return f_val
150150

151151

152-
def power_data_energy_diff(measurement, net_string, f_val, direct_data):
152+
def power_data_energy_diff(
153+
measurement, net_string, f_val, direct_data
154+
) -> dict[str, Any]:
153155
"""Calculate differential energy."""
154156
if "electricity" in measurement and "interval" not in net_string:
155-
diff = 1
157+
diff: int = 1
156158
if "produced" in measurement:
157159
diff = -1
158160
if net_string not in direct_data:
@@ -182,24 +184,24 @@ def __init__(
182184
"""Set the constructor for this class."""
183185
if not websession:
184186

185-
aio_timeout = ClientTimeout(total=timeout)
187+
aio_timeout: ClientTimeout = ClientTimeout(total=timeout)
186188

187189
async def _create_session() -> ClientSession:
188190
return ClientSession(timeout=aio_timeout) # pragma: no cover
189191

190192
loop = asyncio.get_event_loop()
191193
if loop.is_running():
192-
self._websession = ClientSession(timeout=aio_timeout)
194+
self._websession: ClientSession = ClientSession(timeout=aio_timeout)
193195
else:
194196
self._websession = loop.run_until_complete(
195197
_create_session()
196198
) # pragma: no cover
197199
else:
198200
self._websession = websession
199201

200-
self._auth = BasicAuth(username, password=password)
201-
self._endpoint = f"http://{host}:{str(port)}"
202-
self._timeout = timeout
202+
self._auth: BasicAuth = BasicAuth(username, password=password)
203+
self._endpoint: str = f"http://{host}:{str(port)}"
204+
self._timeout: str = timeout
203205

204206
async def _request_validate(self, resp, method):
205207
"""Helper-function for _request(): validate the returned data."""
@@ -229,18 +231,17 @@ async def _request_validate(self, resp, method):
229231

230232
async def _request(
231233
self,
232-
command,
233-
retry=3,
234-
method="get",
235-
data=None,
236-
headers=None,
234+
command: str,
235+
retry: int = 3,
236+
method: str = "get",
237+
data: str = None,
238+
headers: dict[str, str] = None,
237239
):
238240
"""Get/put/delete data from a give URL."""
239241
resp = None
240-
url = f"{self._endpoint}{command}"
242+
url: str = f"{self._endpoint}{command}"
241243

242244
try:
243-
244245
if method == "delete":
245246
resp = await self._websession.delete(url, auth=self._auth)
246247
if method == "get":

0 commit comments

Comments
 (0)