瀏覽代碼

Add effects handler

Bijesh Krishnadas 8 年之前
父節點
當前提交
0c2d548a30
共有 2 個文件被更改,包括 15 次插入1 次删除
  1. 13 0
      lib/MiLight/MiLightClient.cpp
  2. 2 1
      lib/MiLight/MiLightClient.h

+ 13 - 0
lib/MiLight/MiLightClient.cpp

@@ -253,6 +253,11 @@ void MiLightClient::update(const JsonObject& request) {
     }
   }
 
+  //Homeassistant - Handle effect
+  if (request.containsKey("effect")) {
+    this->handleEffect(request["effect"]);
+  }
+
   if (request.containsKey("hue")) {
     this->updateHue(request["hue"]);
   }
@@ -340,6 +345,14 @@ void MiLightClient::handleCommand(const String& command) {
   }
 }
 
+void MiLightClient::handleEffect(const String& effect) {
+  if (effect == "night_mode") {
+    this->enableNightMode();
+  } else if (effect == "white") {
+    this->updateColorWhite();
+  }
+}
+
 uint8_t MiLightClient::parseStatus(const JsonObject& object) {
   String strStatus;
 

+ 2 - 1
lib/MiLight/MiLightClient.h

@@ -67,7 +67,8 @@ public:
 
   void update(const JsonObject& object);
   void handleCommand(const String& command);
-
+  void handleEffect(const String& effect);
+  
   void onPacketSent(PacketSentHandler handler);
 
 protected: