Skip to content

Commit 27683b4

Browse files
Merge pull request #66 from andrey-git/fix-mypy-and-lints
Fixes mypy and linting issues
2 parents c6b5353 + c211761 commit 27683b4

File tree

5 files changed

+33
-47
lines changed

5 files changed

+33
-47
lines changed

examples/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test-files."""

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ ignore = [
434434
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
435435
"N818", # Exception name {name} should be named with an Error suffix
436436
"S101", # Use of assert detected
437-
"TCH001" # Move application import {} into a type-checking block
437+
"TCH001", # Move application import {} into a type-checking block
438+
"N999", # Invalid module name
439+
"FBT003" # Boolean positional value in function call
438440
]
439441
select = ["ALL"]
440442

pysensibo/__init__.py

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Python API for Sensibo."""
2+
23
from __future__ import annotations
3-
import asyncio
4-
from datetime import datetime, timezone
54

5+
import asyncio
66
import json
77
import logging
8+
from datetime import datetime, timezone
89
from typing import Any
910

1011
from aiohttp import ClientResponse, ClientSession
@@ -51,16 +52,15 @@ async def async_get_devices(self, fields: str = "*") -> dict[str, Any]:
5152
params = {"apiKey": self.api_key, "fields": fields}
5253
return await self._get(APIV2 + "/users/me/pods", params)
5354

54-
async def async_get_devices_data(self) -> SensiboData:
55+
async def async_get_devices_data(self) -> SensiboData: # noqa: C901
5556
"""Return dataclass with Sensibo Devices."""
5657
devices: list[dict[str, Any]] = []
5758
data = await self.async_get_devices()
5859
if "result" not in data:
5960
LOGGER.warning("No result in data from devices")
6061
LOGGER.debug("Data without result: %s", data)
6162
raise SensiboError("No result in data")
62-
for device in data["result"]:
63-
devices.append(device)
63+
devices = list(data["result"])
6464

6565
device_data: dict[str, SensiboDevice] = {}
6666
dev: dict[str, Any]
@@ -126,14 +126,14 @@ async def async_get_devices_data(self) -> SensiboData:
126126
ac_states.get("mode"), {}
127127
)
128128
fan_modes: list[str] | None = current_capabilities.get("fanLevels")
129-
fan_modes_translated: dict | None = None
129+
fan_modes_translated: dict[str, str] | None = None
130130
if fan_modes:
131131
fan_modes_translated = {
132132
_fan_mode.lower(): _fan_mode for _fan_mode in fan_modes
133133
}
134134
fan_modes = [_fan_mode.lower() for _fan_mode in fan_modes]
135135
swing_modes: list[str] | None = current_capabilities.get("swing")
136-
swing_modes_translated: dict | None = None
136+
swing_modes_translated: dict[str, str] | None = None
137137
if swing_modes:
138138
swing_modes_translated = {
139139
_swing_mode.lower(): _swing_mode for _swing_mode in swing_modes
@@ -142,7 +142,7 @@ async def async_get_devices_data(self) -> SensiboData:
142142
horizontal_swing_modes: list[str] | None = current_capabilities.get(
143143
"horizontalSwing"
144144
)
145-
horizontal_swing_modes_translated: dict | None = None
145+
horizontal_swing_modes_translated: dict[str, str] | None = None
146146
if horizontal_swing_modes:
147147
horizontal_swing_modes_translated = {
148148
_horizontal_mode.lower(): _horizontal_mode
@@ -153,7 +153,7 @@ async def async_get_devices_data(self) -> SensiboData:
153153
for _horizontal_mode in horizontal_swing_modes
154154
]
155155
light_modes: list[str] | None = current_capabilities.get("light")
156-
light_modes_translated: dict | None = None
156+
light_modes_translated: dict[str, str] | None = None
157157
if light_modes:
158158
light_modes_translated = {
159159
_light_mode.lower(): _light_mode for _light_mode in light_modes
@@ -170,8 +170,7 @@ async def async_get_devices_data(self) -> SensiboData:
170170
if temperatures_list:
171171
diff = MAX_POSSIBLE_STEP
172172
for i in range(len(temperatures_list) - 1):
173-
if temperatures_list[i + 1] - temperatures_list[i] < diff:
174-
diff = temperatures_list[i + 1] - temperatures_list[i]
173+
diff = min(diff, temperatures_list[i + 1] - temperatures_list[i])
175174
temperature_step = diff
176175

177176
active_features = list(ac_states)
@@ -298,10 +297,10 @@ async def async_get_devices_data(self) -> SensiboData:
298297
smart_type = smart_type.lower()
299298
smart_low_temp_threshold = smart.get("lowTemperatureThreshold")
300299
smart_high_temp_threshold = smart.get("highTemperatureThreshold")
301-
_smart_low_state: dict[str | Any] = smart.get("lowTemperatureState", {})
302-
_smart_high_state: dict[str | Any] = smart.get("highTemperatureState", {})
303-
smart_low_state: dict[str | Any] = {}
304-
smart_high_state: dict[str | Any] = {}
300+
_smart_low_state: dict[str, Any] = smart.get("lowTemperatureState", {})
301+
_smart_high_state: dict[str, Any] = smart.get("highTemperatureState", {})
302+
smart_low_state: dict[str, Any] = {}
303+
smart_high_state: dict[str, Any] = {}
305304
if _smart_low_state:
306305
for key, value in _smart_low_state.items():
307306
smart_low_state[key.lower()] = (
@@ -615,12 +614,12 @@ async def _get(
615614
path, params=params, timeout=self.timeout
616615
) as resp:
617616
return await self._response(resp)
618-
except Exception as error:
617+
except Exception:
619618
LOGGER.debug("Retry %d on path %s", 4 - retry, path)
620619
if retry > 0:
621620
await asyncio.sleep(7)
622621
return await self._get(path, params, retry - 1)
623-
raise error
622+
raise
624623

625624
async def _put(
626625
self,
@@ -635,11 +634,11 @@ async def _put(
635634
path, params=params, data=json.dumps(data), timeout=self.timeout
636635
) as resp:
637636
return await self._response(resp)
638-
except Exception as error:
637+
except Exception:
639638
if retry is False:
640639
await asyncio.sleep(5)
641640
return await self._put(path, params, data, True)
642-
raise error
641+
raise
643642

644643
async def _post(
645644
self,
@@ -655,11 +654,11 @@ async def _post(
655654
path, params=params, data=json.dumps(data), timeout=self.timeout
656655
) as resp:
657656
return await self._response(resp)
658-
except Exception as error:
657+
except Exception:
659658
if retry is False:
660659
await asyncio.sleep(5)
661660
return await self._post(path, params, data, True)
662-
raise error
661+
raise
663662

664663
async def _patch(
665664
self,
@@ -675,11 +674,11 @@ async def _patch(
675674
path, params=params, data=json.dumps(data), timeout=self.timeout
676675
) as resp:
677676
return await self._response(resp)
678-
except Exception as error:
677+
except Exception:
679678
if retry is False:
680679
await asyncio.sleep(5)
681680
return await self._patch(path, params, data, True)
682-
raise error
681+
raise
683682

684683
async def _delete(
685684
self, path: str, params: dict[str, Any], retry: bool = False
@@ -691,11 +690,11 @@ async def _delete(
691690
path, params=params, timeout=self.timeout
692691
) as resp:
693692
return await self._response(resp)
694-
except Exception as error:
693+
except Exception:
695694
if retry is False:
696695
await asyncio.sleep(5)
697696
return await self._delete(path, params, True)
698-
raise error
697+
raise
699698

700699
async def _response(self, resp: ClientResponse) -> dict[str, Any]:
701700
"""Return response from call."""

pysensibo/model.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Data classes for Sensibo."""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass
@@ -38,13 +39,13 @@ class SensiboDevice:
3839
available: bool
3940
hvac_modes: list[str] | None
4041
fan_modes: list[str] | None
41-
fan_modes_translated: dict | None
42+
fan_modes_translated: dict[str, str] | None
4243
swing_modes: list[str] | None
43-
swing_modes_translated: dict | None
44+
swing_modes_translated: dict[str, str] | None
4445
horizontal_swing_modes: list[str] | None
45-
horizontal_swing_modes_translated: dict | None
46+
horizontal_swing_modes_translated: dict[str, str] | None
4647
light_modes: list[str] | None
47-
light_modes_translated: dict | None
48+
light_modes_translated: dict[str, str] | None
4849
temp_unit: str | None
4950
temp_list: list[int]
5051
temp_step: int

test-files/test.py

-17
This file was deleted.

0 commit comments

Comments
 (0)