Skip to content

Commit 9b45975

Browse files
committed
chore(core): reformat
1 parent 6f964c1 commit 9b45975

File tree

6 files changed

+49
-43
lines changed

6 files changed

+49
-43
lines changed

plugp100/discovery/discovered_device.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ async def get_tapo_device(
8585
)
8686
else:
8787
logging.warning(
88-
f"No encryption schema found for discovered device {self.ip} {self.device_type}")
88+
f"No encryption schema found for discovered device {self.ip} {self.device_type}"
89+
)
8990
config = DeviceConnectConfiguration(
90-
host=self.ip, port=80, device_type=self.device_type, credentials=credentials
91+
host=self.ip,
92+
port=80,
93+
device_type=self.device_type,
94+
credentials=credentials,
9195
)
9296
return await connect(config, session)
9397

plugp100/new/components/countdown.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,41 @@
88

99

1010
class Countdown(DeviceComponent):
11-
1211
def __init__(self, client: TapoClient):
1312
self._client = client
14-
self._rules: TapoRuleList[RuleTimer] = TapoRuleList(enable=True, countdown_rule_max_count=1, rule_list=[])
13+
self._rules: TapoRuleList[RuleTimer] = TapoRuleList(
14+
enable=True, countdown_rule_max_count=1, rule_list=[]
15+
)
1516

1617
async def update(self, current_state: dict[str, Any] | None = None):
1718
request = TapoRequest(method="get_countdown_rules", params={"start_index": 0})
18-
self._rules = (await self._client.execute_raw_request(request)) \
19-
.map(lambda x: TapoRuleList.from_json(x, RuleTimer)) \
19+
self._rules = (
20+
(await self._client.execute_raw_request(request))
21+
.map(lambda x: TapoRuleList.from_json(x, RuleTimer))
2022
.get_or_else(self._rules)
23+
)
2124

2225
def get_countdown_rules(self) -> "TapoRuleList[RuleTimer]":
2326
return self._rules
2427

2528
async def add_countdown_on(self, timer_seconds: int) -> Try[bool]:
26-
return await self._add_countdown_rule(timer_seconds, {
27-
'on': True
28-
})
29+
return await self._add_countdown_rule(timer_seconds, {"on": True})
2930

3031
async def add_countdown_off(self, timer_seconds: int) -> Try[bool]:
31-
return await self._add_countdown_rule(timer_seconds, {
32-
'on': False
33-
})
34-
35-
async def _add_countdown_rule(self, timer_seconds: int, desired_state: dict[str, Any]) -> Try[bool]:
36-
request = TapoRequest(method="add_countdown_rule", params={
37-
"delay": timer_seconds,
38-
"desired_states": desired_state,
39-
"enable": True,
40-
})
41-
return (await self._client.execute_raw_request(request)) \
42-
.map(lambda _: True)
32+
return await self._add_countdown_rule(timer_seconds, {"on": False})
33+
34+
async def _add_countdown_rule(
35+
self, timer_seconds: int, desired_state: dict[str, Any]
36+
) -> Try[bool]:
37+
request = TapoRequest(
38+
method="add_countdown_rule",
39+
params={
40+
"delay": timer_seconds,
41+
"desired_states": desired_state,
42+
"enable": True,
43+
},
44+
)
45+
return (await self._client.execute_raw_request(request)).map(lambda _: True)
4346

4447

4548
T = TypeVar("T")
@@ -56,10 +59,7 @@ def from_json(data: dict[str, Any], constructor: T) -> "TapoRuleList[T]":
5659
return TapoRuleList(
5760
enable=data.get("enable", False),
5861
countdown_rule_max_count=data.get("countdown_rule_max_count", 1),
59-
rule_list=list(map(
60-
lambda x: constructor(**x),
61-
data.get('rule_list', [])
62-
))
62+
rule_list=list(map(lambda x: constructor(**x), data.get("rule_list", []))),
6363
)
6464

6565

plugp100/new/components/hub_children_component.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ async def update(self, current_state: dict[str, Any] | None = None):
3939
if child_device is not None:
4040
self._children.append(child_device)
4141
else:
42-
_LOGGER.warning(f"Found child device not supported, model {child.model}", )
4342
_LOGGER.warning(
44-
"Please request support by opening an issue to https://github.com/petretiandrea/plugp100/issues/new")
43+
f"Found child device not supported, model {child.model}",
44+
)
45+
_LOGGER.warning(
46+
"Please request support by opening an issue to https://github.com/petretiandrea/plugp100/issues/new"
47+
)
4548

4649
for child_device in self._children:
4750
await child_device.update()
@@ -52,17 +55,17 @@ def find_child_device_by_model(self, model_filter: str) -> Optional["TapoDevice"
5255
child
5356
for child in self.children
5457
if child.device_id is not None
55-
and model_filter.lower() in child.model.lower()
58+
and model_filter.lower() in child.model.lower()
5659
),
5760
None,
5861
)
5962

6063

6164
# TODO: make based on device type
6265
def _hub_child_create(
63-
parent_device: TapoDevice,
64-
client: TapoClient,
65-
child_info: HubChildBaseInfo,
66+
parent_device: TapoDevice,
67+
client: TapoClient,
68+
child_info: HubChildBaseInfo,
6669
) -> Optional[TapoDevice]:
6770
model = child_info.model.lower()
6871
if "t31" in model:

plugp100/new/device_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ async def _guess_protocol(
9090
KlapProtocol(config.credentials, config.url, klap_handshake_v2(), session),
9191
]
9292
device_info_request = TapoRequest.get_device_info()
93-
for i,protocol in enumerate(protocols):
93+
for i, protocol in enumerate(protocols):
9494
info = await protocol.send_request(device_info_request)
9595
if info.is_success():
9696
_LOGGER.debug(f"Found working protocol {type(protocol)}")
97-
for j,p in enumerate(protocols):
97+
for j, p in enumerate(protocols):
9898
if i != j:
9999
await p.close()
100100
return protocol

plugp100/new/tapodevice.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class LastUpdate:
2727

2828
class TapoDevice:
2929
def __init__(
30-
self,
31-
host: str,
32-
port: Optional[int],
33-
client: TapoClient,
34-
device_type: DeviceType = DeviceType.Unknown,
35-
child_id: Optional[str] = None,
30+
self,
31+
host: str,
32+
port: Optional[int],
33+
client: TapoClient,
34+
device_type: DeviceType = DeviceType.Unknown,
35+
child_id: Optional[str] = None,
3636
):
3737
self.host = host
3838
self.port = port
@@ -171,8 +171,7 @@ async def start_firmware_upgrade(self) -> bool:
171171
response = await self.client.control_child(self._child_id, request)
172172
else:
173173
response = await self.client.execute_raw_request(request)
174-
return response.map(lambda _: True) \
175-
.get_or_else(False)
174+
return response.map(lambda _: True).get_or_else(False)
176175

177176
async def _negotiate_components(self) -> Components:
178177
if self._child_id:

plugp100/responses/firmware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FirmwareDownloadStatus(enum.Enum):
3333
DOWNLOAD_FAIL = -1001
3434
CHECK_FAIL = -1002
3535
TRANSFER_FAIL = -1003
36-
LOW_BATTERY = - 1004
36+
LOW_BATTERY = -1004
3737

3838

3939
@dataclasses.dataclass
@@ -51,5 +51,5 @@ def from_json(data: dict[str, Any]) -> "FirmwareDownloadProgress":
5151
download_in_progress=data.get("download_progress", 0),
5252
reboot_time=data.get("reboot_time", 0),
5353
upgrade_time=data.get("upgrade_time", 0),
54-
auto_upgrade=data.get("auto_upgrade", False)
54+
auto_upgrade=data.get("auto_upgrade", False),
5555
)

0 commit comments

Comments
 (0)