Explorar el Código

Merge branch '1.9.0' into integration_tests

Christopher Mullins hace 6 años
padre
commit
ee50a7f437

+ 1 - 0
README.md

@@ -174,6 +174,7 @@ Route (5) supports these commands. Note that each bulb type has support for a di
    * `temperature_down`. Turns down the white temperature. Not all bulbs with adjustable white temperature support this command.
    * `temperature_up`. Turns up the white temperature. Not all bulbs with adjustable white temperature support this command.
    * `night_mode`. Enable "night mode", which is minimum brightness and bulbs only responding to on/off commands.
+   * `toggle`. Toggle on/off state.
 1. `commands`. An array containing any number of the above commands (including repeats).
 
 The following redundant commands are supported for the sake of compatibility with HomeAssistant's [`mqtt`](https://home-assistant.io/components/light.mqtt/) light platform with the `json` schema:

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 2
dist/index.html.gz.h


+ 1 - 1
lib/MiLight/CctPacketFormatter.h

@@ -26,7 +26,7 @@ enum MiLightCctButton {
 class CctPacketFormatter : public PacketFormatter {
 public:
   CctPacketFormatter()
-    : PacketFormatter(7, 20)
+    : PacketFormatter(REMOTE_TYPE_CCT, 7, 20)
   { }
 
   virtual bool canHandle(const uint8_t* packet, const size_t len);

+ 1 - 1
lib/MiLight/FUT089PacketFormatter.h

@@ -24,7 +24,7 @@ enum MiLightFUT089Arguments {
 class FUT089PacketFormatter : public V2PacketFormatter {
 public:
   FUT089PacketFormatter()
-    : V2PacketFormatter(0x25, 8)    // protocol is 0x25, and there are 8 groups
+    : V2PacketFormatter(REMOTE_TYPE_FUT089, 0x25, 8)    // protocol is 0x25, and there are 8 groups
   { }
 
   virtual void updateBrightness(uint8_t value);

+ 1 - 1
lib/MiLight/FUT091PacketFormatter.h

@@ -12,7 +12,7 @@ enum class FUT091Command {
 class FUT091PacketFormatter : public V2PacketFormatter {
 public:
   FUT091PacketFormatter()
-    : V2PacketFormatter(0x21, 4)    // protocol is 0x21, and there are 4 groups
+    : V2PacketFormatter(REMOTE_TYPE_FUT091, 0x21, 4)    // protocol is 0x21, and there are 4 groups
   { }
 
   virtual void updateBrightness(uint8_t value);

+ 10 - 0
lib/MiLight/MiLightClient.cpp

@@ -322,6 +322,14 @@ void MiLightClient::command(uint8_t command, uint8_t arg) {
   flushPacket();
 }
 
+void MiLightClient::toggleStatus() {
+#ifdef DEBUG_CLIENT_COMMANDS
+  Serial.printf_P(PSTR("MiLightClient::toggleStatus"));
+#endif
+  currentRemote->packetFormatter->toggleStatus();
+  flushPacket();
+}
+
 void MiLightClient::update(const JsonObject& request) {
   if (this->updateBeginHandler) {
     this->updateBeginHandler();
@@ -472,6 +480,8 @@ void MiLightClient::handleCommand(const String& command) {
     this->modeSpeedDown();
   } else if (command == "mode_speed_up") {
     this->modeSpeedUp();
+  } else if (command == "toggle") {
+    this->toggleStatus();
   }
 }
 

+ 1 - 0
lib/MiLight/MiLightClient.h

@@ -54,6 +54,7 @@ public:
   void previousMode();
   void modeSpeedDown();
   void modeSpeedUp();
+  void toggleStatus();
 
   // RGBW methods
   void updateHue(const uint16_t hue);

+ 15 - 2
lib/MiLight/PacketFormatter.cpp

@@ -19,8 +19,9 @@ uint8_t* PacketStream::next() {
   return packet;
 }
 
-PacketFormatter::PacketFormatter(const size_t packetLength, const size_t maxPackets)
-  : packetLength(packetLength),
+PacketFormatter::PacketFormatter(const MiLightRemoteType deviceType, const size_t packetLength, const size_t maxPackets)
+  : deviceType(deviceType),
+    packetLength(packetLength),
     numPackets(0),
     currentPacket(NULL),
     held(false)
@@ -43,6 +44,18 @@ void PacketFormatter::updateStatus(MiLightStatus status) {
   updateStatus(status, groupId);
 }
 
+void PacketFormatter::toggleStatus() {
+  const GroupState* state = stateStore->get(deviceId, groupId, deviceType);
+
+  if (state) {
+    if (state->isSetState() && state->getState() == MiLightStatus::ON) {
+      updateStatus(MiLightStatus::OFF);
+    } else {
+      updateStatus(MiLightStatus::ON);
+    }
+  }
+}
+
 void PacketFormatter::setHeld(bool held) {
   this->held = held;
 }

+ 3 - 1
lib/MiLight/PacketFormatter.h

@@ -29,7 +29,7 @@ struct PacketStream {
 
 class PacketFormatter {
 public:
-  PacketFormatter(const size_t packetLength, const size_t maxPackets = 1);
+  PacketFormatter(const MiLightRemoteType deviceType, const size_t packetLength, const size_t maxPackets = 1);
 
   // Ideally these would be constructor parameters.  We could accomplish this by
   // wrapping PacketFormaters in a factory, as Settings and StateStore are not
@@ -43,6 +43,7 @@ public:
   virtual bool canHandle(const uint8_t* packet, const size_t len);
 
   void updateStatus(MiLightStatus status);
+  void toggleStatus();
   virtual void updateStatus(MiLightStatus status, uint8_t groupId);
   virtual void command(uint8_t command, uint8_t arg);
 
@@ -99,6 +100,7 @@ protected:
   PacketStream packetStream;
   GroupStateStore* stateStore = NULL;
   const Settings* settings = NULL;
+  const MiLightRemoteType deviceType;
 
   void pushPacket();
 

+ 1 - 1
lib/MiLight/RgbCctPacketFormatter.h

@@ -32,7 +32,7 @@ enum MiLightRgbCctArguments {
 class RgbCctPacketFormatter : public V2PacketFormatter {
 public:
   RgbCctPacketFormatter()
-    : V2PacketFormatter(0x20, 4),
+    : V2PacketFormatter(REMOTE_TYPE_RGB_CCT, 0x20, 4),
       lastMode(0)
   { }
 

+ 1 - 1
lib/MiLight/RgbPacketFormatter.h

@@ -22,7 +22,7 @@ enum MiLightRgbButton {
 class RgbPacketFormatter : public PacketFormatter {
 public:
   RgbPacketFormatter()
-    : PacketFormatter(6, 20)
+    : PacketFormatter(REMOTE_TYPE_RGB, 6, 20)
   { }
 
   virtual void updateStatus(MiLightStatus status, uint8_t groupId);

+ 1 - 1
lib/MiLight/RgbwPacketFormatter.h

@@ -52,7 +52,7 @@ enum MiLightRgbwButton {
 class RgbwPacketFormatter : public PacketFormatter {
 public:
   RgbwPacketFormatter()
-    : PacketFormatter(7)
+    : PacketFormatter(REMOTE_TYPE_RGBW, 7)
   { }
 
   virtual bool canHandle(const uint8_t* packet, const size_t len);

+ 7 - 2
lib/MiLight/V2PacketFormatter.cpp

@@ -3,8 +3,8 @@
 
 #define GROUP_COMMAND_ARG(status, groupId, numGroups) ( groupId + (status == OFF ? (numGroups + 1) : 0) )
 
-V2PacketFormatter::V2PacketFormatter(uint8_t protocolId, uint8_t numGroups)
-  : PacketFormatter(9),
+V2PacketFormatter::V2PacketFormatter(const MiLightRemoteType deviceType, uint8_t protocolId, uint8_t numGroups)
+  : PacketFormatter(deviceType, 9),
     protocolId(protocolId),
     numGroups(numGroups)
 { }
@@ -13,6 +13,11 @@ bool V2PacketFormatter::canHandle(const uint8_t *packet, const size_t packetLen)
   uint8_t packetCopy[V2_PACKET_LEN];
   memcpy(packetCopy, packet, V2_PACKET_LEN);
   V2RFEncoding::decodeV2Packet(packetCopy);
+
+#ifdef DEBUG_PRINTF
+  Serial.printf_P(PSTR("Testing whether formater for ID %d can handle packet: with protocol ID %d...\n"), protocolId, packetCopy[V2_PROTOCOL_ID_INDEX]);
+#endif
+
   return packetCopy[V2_PROTOCOL_ID_INDEX] == protocolId;
 }
 

+ 1 - 1
lib/MiLight/V2PacketFormatter.h

@@ -15,7 +15,7 @@
 
 class V2PacketFormatter : public PacketFormatter {
 public:
-  V2PacketFormatter(uint8_t protocolId, uint8_t numGroups);
+  V2PacketFormatter(const MiLightRemoteType deviceType, uint8_t protocolId, uint8_t numGroups);
 
   virtual bool canHandle(const uint8_t* packet, const size_t packetLen);
   virtual void initializePacket(uint8_t* packet);