Skip to content

Commit 92f2a0f

Browse files
committed
Merge if statements with enclosing one
1 parent 74286fb commit 92f2a0f

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

plugwise_usb/connection/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ async def _handle_stick_event(self, event: StickEvent) -> None:
156156
if not self._queue.is_running:
157157
self._queue.start(self._manager)
158158
await self.initialize_stick()
159-
elif event == StickEvent.DISCONNECTED:
160-
if self._queue.is_running:
161-
await self._queue.stop()
159+
elif event == StickEvent.DISCONNECTED and self._queue.is_running:
160+
await self._queue.stop()
162161

163162
async def initialize_stick(self) -> None:
164163
"""Initialize connection to the USB-stick."""

plugwise_usb/nodes/circle.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,15 +1087,14 @@ def _correct_power_pulses(self, pulses: int, offset: int) -> float:
10871087
async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any]:
10881088
"""Update latest state for given feature."""
10891089
states: dict[NodeFeature, Any] = {}
1090-
if not self._available:
1091-
if not await self.is_online():
1092-
_LOGGER.debug(
1093-
"Node %s did not respond, unable to update state", self._mac_in_str
1094-
)
1095-
for feature in features:
1096-
states[feature] = None
1097-
states[NodeFeature.AVAILABLE] = self.available_state
1098-
return states
1090+
if not self._available and not await self.is_online():
1091+
_LOGGER.debug(
1092+
"Node %s did not respond, unable to update state", self._mac_in_str
1093+
)
1094+
for feature in features:
1095+
states[feature] = None
1096+
states[NodeFeature.AVAILABLE] = self.available_state
1097+
return states
10991098

11001099
for feature in features:
11011100
if feature not in self._features:

plugwise_usb/nodes/helpers/counter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ def add_pulse_log( # pylint: disable=too-many-arguments
8282
"""Add pulse log."""
8383
if self._pulse_collection.add_log(
8484
address, slot, timestamp, pulses, import_only
85-
):
86-
if not import_only:
87-
self.update()
85+
) and not import_only:
86+
self.update()
8887

8988
def get_pulse_logs(self) -> dict[int, dict[int, PulseLogRecord]]:
9089
"""Return currently collected pulse logs."""

plugwise_usb/nodes/node.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ def _setup_protocol(
337337
for feature in node_features:
338338
if (
339339
required_version := FEATURE_SUPPORTED_AT_FIRMWARE.get(feature)
340-
) is not None:
341-
if (
342-
self._node_protocols.min
343-
<= required_version
344-
<= self._node_protocols.max
345-
and feature not in self._features
346-
):
347-
self._features += (feature,)
340+
) is not None and (
341+
self._node_protocols.min
342+
<= required_version
343+
<= self._node_protocols.max
344+
and feature not in self._features
345+
):
346+
self._features += (feature,)
347+
348348
self._node_info.features = self._features
349349

350350
async def reconnect(self) -> None:

plugwise_usb/nodes/scan.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,12 @@ def _daylight_mode_from_cache(self) -> bool:
166166
def _motion_from_cache(self) -> bool:
167167
"""Load motion state from cache."""
168168
if (cached_motion_state := self._get_cache(CACHE_MOTION_STATE)) is not None:
169-
if cached_motion_state == "True":
170-
if (
171-
motion_timestamp := self._motion_timestamp_from_cache()
172-
) is not None:
173-
if (
174-
datetime.now(tz=UTC) - motion_timestamp
175-
).seconds < self._reset_timer_from_cache() * 60:
176-
return True
169+
if (
170+
cached_motion_state == "True"
171+
and (motion_timestamp := self._motion_timestamp_from_cache()) is not None
172+
and (datetime.now(tz=UTC) - motion_timestamp).seconds < self._reset_timer_from_cache() * 60
173+
):
174+
return True
177175
return False
178176
return SCAN_DEFAULT_MOTION_STATE
179177

0 commit comments

Comments
 (0)