1
0
Преглед на файлове

log outcome of sent command

Fabian Peter Hammerle преди 4 години
родител
ревизия
85f6a05fab
променени са 1 файла, в които са добавени 8 реда и са изтрити 2 реда
  1. 8 2
      switchbot_mqtt/__init__.py

+ 8 - 2
switchbot_mqtt/__init__.py

@@ -79,9 +79,15 @@ def _mqtt_on_message(
     # TODO validate mac address
     switchbot_device = switchbot.Switchbot(mac=switchbot_mac_address)
     if message.payload.lower() == b"on":
-        print("TODO", switchbot_device.turn_on())
+        if not switchbot_device.turn_on():
+            _LOGGER.error("failed to turn on switchbot %s", switchbot_mac_address)
+        else:
+            _LOGGER.info("switchbot %s turned on", switchbot_mac_address)
     elif message.payload.lower() == b"off":
-        print("TODO", switchbot_device.turn_off())
+        if not switchbot_device.turn_off():
+            _LOGGER.error("failed to turn off switchbot %s", switchbot_mac_address)
+        else:
+            _LOGGER.info("switchbot %s turned off", switchbot_mac_address)
     else:
         _LOGGER.warning("unexpected payload %r", message.payload)