Bladeren bron

add field to better support HASS effects (#199)

Brett Bartrum 7 jaren geleden
bovenliggende
commit
32cb00ed37

File diff suppressed because it is too large
+ 2 - 2
dist/index.html.gz.h


+ 3 - 1
lib/MiLight/MiLightClient.cpp

@@ -381,8 +381,10 @@ void MiLightClient::handleCommand(const String& command) {
 void MiLightClient::handleEffect(const String& effect) {
   if (effect == "night_mode") {
     this->enableNightMode();
-  } else if (effect == "white") {
+  } else if (effect == "white" || effect == "white_mode") {
     this->updateColorWhite();
+  } else { // assume we're trying to set mode
+    this->updateMode(effect.toInt());
   }
 }
 

+ 16 - 0
lib/MiLightState/GroupState.cpp

@@ -96,6 +96,8 @@ bool GroupState::isSetField(GroupStateField field) const {
       return isSetSaturation();
     case GroupStateField::MODE:
       return isSetMode();
+    case GroupStateField::EFFECT:
+      return isSetEffect();
     case GroupStateField::KELVIN:
     case GroupStateField::COLOR_TEMP:
       return isSetKelvin();
@@ -213,6 +215,10 @@ bool GroupState::setSaturation(uint8_t saturation) {
 }
 
 bool GroupState::isSetMode() const { return state.fields._isSetMode; }
+bool GroupState::isSetEffect() const {
+  // only BULB_MODE_COLOR does not have an effect.
+  return isSetBulbMode() && getBulbMode() != BULB_MODE_COLOR;
+}
 uint8_t GroupState::getMode() const { return state.fields._mode; }
 bool GroupState::setMode(uint8_t mode) {
   if (isSetMode() && getMode() == mode) {
@@ -431,6 +437,16 @@ void GroupState::applyField(JsonObject& partialState, GroupStateField field) {
         }
         break;
 
+      case GroupStateField::EFFECT:
+        if (getBulbMode() == BULB_MODE_SCENE) {
+          partialState["effect"] = String(getMode());
+        } else if (getBulbMode() == BULB_MODE_WHITE) {
+          partialState["effect"] = "white_mode";
+        } else if (getBulbMode() == BULB_MODE_NIGHT) {
+          partialState["effect"] = "night_mode";
+        }
+        break;
+
       case GroupStateField::COLOR_TEMP:
         if (getBulbMode() == BULB_MODE_WHITE) {
           partialState["color_temp"] = getMireds();

+ 1 - 0
lib/MiLightState/GroupState.h

@@ -62,6 +62,7 @@ public:
 
   // 5 bits
   bool isSetMode() const;
+  bool isSetEffect() const;
   uint8_t getMode() const;
   bool setMode(uint8_t mode);
 

+ 4 - 2
lib/Types/GroupStateField.h

@@ -14,7 +14,8 @@ static const char* STATE_NAMES[] = {
   "kelvin",
   "color_temp",
   "bulb_mode",
-  "computed_color"
+  "computed_color",
+  "effect"
 };
 
 enum class GroupStateField {
@@ -30,7 +31,8 @@ enum class GroupStateField {
   KELVIN,
   COLOR_TEMP,
   BULB_MODE,
-  COMPUTED_COLOR
+  COMPUTED_COLOR,
+  EFFECT
 };
 
 class GroupStateFieldHelpers {

+ 2 - 1
web/src/js/script.js

@@ -26,7 +26,8 @@ var GROUP_STATE_KEYS = [
   "kelvin",
   "color_temp",
   "bulb_mode",
-  "computed_color"
+  "computed_color",
+  "effect"
 ];
 
 var FORM_SETTINGS_HELP = {