소스 검색

More logging

Daniel Høyer Iversen 6 년 전
부모
커밋
08146ff89f
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      switchbot/__init__.py

+ 5 - 1
switchbot/__init__.py

@@ -21,15 +21,19 @@ class Switchbot:
 
     def _sendpacket(self, key, retry=2) -> bool:
         try:
+            _LOGGER.debug("Connecting")
             device = bluepy.btle.Peripheral(self._mac,
                                             bluepy.btle.ADDR_TYPE_RANDOM)
             hand_service = device.getServiceByUUID(UUID)
             hand = hand_service.getCharacteristics(HANDLE)[0]
+            _LOGGER.debug("Sending command, %s", key)
             hand.write(binascii.a2b_hex(key))
+            _LOGGER.debug("Disconnecting")
             device.disconnect()
         except bluepy.btle.BTLEException:
-            _LOGGER.error("Cannot connect to switchbot.", exc_info=True)
+            _LOGGER.error("Cannot connect to switchbot. Retrying", exc_info=True)
             if retry < 1:
+                _LOGGER.error("Cannot connect to switchbot.", exc_info=True)
                 return False
             return self._sendpacket(key, retry-1)
         return True