Skip to content

Commit 283afaf

Browse files
committed
Use walrus operator
1 parent 2bb3f29 commit 283afaf

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

plugwise_usb/network/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ async def node_awake_message(self, response: PlugwiseResponse) -> bool:
223223
await self._notify_node_event_subscribers(NodeEvent.AWAKE, mac)
224224
self._awake_discovery[mac] = response.timestamp
225225
return True
226-
address = self._register.network_address(mac)
227-
if address is None:
226+
if (address := self._register.network_address(mac)) is None:
228227
if self._register.scan_completed:
229228
return True
230229
_LOGGER.debug(
@@ -540,7 +539,7 @@ async def allow_join_requests(self, state: bool) -> None:
540539
"""Enable or disable Plugwise network."""
541540
request = CirclePlusAllowJoiningRequest(self._controller.send, state)
542541
response = await request.send()
543-
if response is None:
542+
if (response := await request.send()) is None:
544543
raise NodeError("No response to get notifications for join request.")
545544
if response.response_type != NodeResponseType.JOIN_ACCEPTED:
546545
raise MessageError(

plugwise_usb/nodes/circle.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async def calibration_update(self) -> bool:
185185
)
186186
request = EnergyCalibrationRequest(self._send, self._mac_in_bytes)
187187
calibration_response = await request.send()
188-
if calibration_response is None:
188+
if (calibration_response := await request.send()) is None:
189189
_LOGGER.warning(
190190
"Retrieving energy calibration information for %s failed",
191191
self.name,
@@ -494,7 +494,7 @@ async def energy_log_update(self, address: int | None) -> bool:
494494
)
495495
request = CircleEnergyLogsRequest(self._send, self._mac_in_bytes, address)
496496
response = await request.send()
497-
if response is None:
497+
if (response := await request.send()) is None:
498498
_LOGGER.debug(
499499
"Retrieving of energy log at address %s for node %s failed",
500500
str(address),
@@ -529,7 +529,7 @@ async def energy_log_update(self, address: int | None) -> bool:
529529
async def _energy_log_records_load_from_cache(self) -> bool:
530530
"""Load energy_log_record from cache."""
531531
cache_data = self._get_cache(CACHE_ENERGY_COLLECTION)
532-
if cache_data is None:
532+
if (cache_data := self._get_cache(CACHE_ENERGY_COLLECTION)) is None:
533533
_LOGGER.debug(
534534
"Failed to restore energy log records from cache for node %s", self.name
535535
)
@@ -730,8 +730,7 @@ async def clock_synchronize(self) -> bool:
730730
self._node_protocols.max,
731731
)
732732
node_response: NodeResponse | None = await set_clock_request.send()
733-
734-
if node_response is None:
733+
if (node_response := await set_clock_request.send()) is None:
735734
_LOGGER.warning(
736735
"Failed to (re)set the internal clock of %s",
737736
self.name,

plugwise_usb/nodes/circle_plus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def clock_synchronize(self) -> bool:
8484
self._send, self._mac_in_bytes
8585
)
8686
clock_response = await clock_request.send()
87-
if clock_response is None:
87+
if (clock_response := await clock_request.send()) is None:
8888
_LOGGER.debug(
8989
"No response for async_realtime_clock_synchronize() for %s", self.mac
9090
)

plugwise_usb/nodes/sed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ async def sed_configure( #pylint: disable=too-many-arguments
685685
sleep_duration,
686686
)
687687
response = await request.send()
688-
if response is None:
688+
if (response := await request.send()) is None:
689689
self._new_battery_config = BatteryConfig()
690690
_LOGGER.warning(
691691
"No response from %s to configure sleep settings request", self.name

0 commit comments

Comments
 (0)