Skip to content

Commit b0d05a4

Browse files
committed
remove repeated logmessages by pushing into function
1 parent a3178a4 commit b0d05a4

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

plugwise_usb/nodes/sense.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -738,27 +738,18 @@ async def _configure_sense_humidity_task(self) -> bool:
738738
self.humidity_direction,
739739
)
740740
if (response := await request.send()) is None:
741-
_LOGGER.warning(
742-
"No response from %s to configure humidity hysteresis settings request",
743-
self.name,
744-
)
741+
self._log_configure_failed("humidity hysteresis")
745742
return False
746743
if response.node_ack_type == NodeAckResponseType.SENSE_BOUNDARIES_FAILED:
747744
_LOGGER.warning(
748745
"Failed to configure humidity hysteresis settings for %s", self.name
749746
)
750747
return False
751748
if response.node_ack_type == NodeAckResponseType.SENSE_BOUNDARIES_ACCEPTED:
752-
_LOGGER.debug(
753-
"Successful configure humidity hysteresis settings for %s", self.name
754-
)
749+
self._log_configure_success("humidity hysteresis")
755750
return True
756751

757-
_LOGGER.warning(
758-
"Unexpected response ack type %s for %s",
759-
response.node_ack_type,
760-
self.name,
761-
)
752+
self._log_unexpected_response_ack(response.node_ack_type)
762753
return False
763754

764755
async def _configure_sense_temperature_task(self) -> bool:
@@ -798,21 +789,13 @@ async def _configure_sense_temperature_task(self) -> bool:
798789
)
799790
return False
800791
if response.node_ack_type == NodeAckResponseType.SENSE_BOUNDARIES_FAILED:
801-
_LOGGER.warning(
802-
"Failed to configure temperature hysteresis settings for %s", self.name
803-
)
792+
self._log_configure_failed("temperature hysteresis")
804793
return False
805794
if response.node_ack_type == NodeAckResponseType.SENSE_BOUNDARIES_ACCEPTED:
806-
_LOGGER.debug(
807-
"Successful configure temperature hysteresis settings for %s", self.name
808-
)
795+
self._log_configure_success("temperature hysteresis")
809796
return True
810797

811-
_LOGGER.warning(
812-
"Unexpected response ack type %s for %s",
813-
response.node_ack_type,
814-
self.name,
815-
)
798+
self._log_unexpected_response_ack(response.node_ack_type)
816799
return False
817800

818801
async def _configure_sense_report_interval_task(self) -> bool:
@@ -831,18 +814,30 @@ async def _configure_sense_report_interval_task(self) -> bool:
831814
)
832815
return False
833816
if response.node_ack_type == NodeAckResponseType.SENSE_INTERVAL_FAILED:
834-
_LOGGER.warning("Failed to configure report interval for %s", self.name)
817+
self._log_configure_failed("report interval")
835818
return False
836819
if response.node_ack_type == NodeAckResponseType.SENSE_INTERVAL_ACCEPTED:
837-
_LOGGER.debug("Successful configure report interval for %s", self.name)
820+
self._log_configure_success("report interval")
838821
return True
839822

823+
self._log_unexpected_response_ack(response.node_ack_type)
824+
return False
825+
826+
def _log_unexpected_response_ack(self, response: NodeAckResponseType) -> None:
827+
"""Log unexpected response."""
840828
_LOGGER.warning(
841829
"Unexpected response ack type %s for %s",
842830
response.node_ack_type,
843831
self.name,
844832
)
845-
return False
833+
834+
def _log_configure_failed(self, parameter: str) -> None:
835+
"""Log configuration failed."""
836+
_LOGGER.warning("Failed to configure %s for %s", parameter, self.name)
837+
838+
def _log_configure_success(self, parameter: str) -> None:
839+
"""Log configuration success."""
840+
_LOGGER.debug("Successful configure %s for %s", parameter, self.name)
846841

847842
async def _sense_configure_update(self) -> None:
848843
"""Push sense configuration update to cache."""

0 commit comments

Comments
 (0)