Explorar o código

Fix compiler warnings

Christopher Mullins %!s(int64=6) %!d(string=hai) anos
pai
achega
644666478f

+ 3 - 3
lib/DataStructures/LinkedList.h

@@ -28,7 +28,7 @@ template <typename T>
 class LinkedList {
 
 protected:
-  int _size;
+  size_t _size;
   ListNode<T> *root;
   ListNode<T>  *last;
 
@@ -39,7 +39,7 @@ public:
   /*
     Returns current size of LinkedList
   */
-  virtual int size() const;
+  virtual size_t size() const;
   /*
     Adds a T object in the specified index;
     Unlink and link the LinkedList correcly;
@@ -159,7 +159,7 @@ ListNode<T>* LinkedList<T>::getNode(int index){
 }
 
 template<typename T>
-int LinkedList<T>::size() const{
+size_t LinkedList<T>::size() const{
   return _size;
 }
 

+ 1 - 1
lib/Helpers/IntParsing.h

@@ -60,7 +60,7 @@ public:
   static void bytesToHexStr(const uint8_t* bytes, const size_t len, char* buffer, size_t maxLen) {
     char* p = buffer;
 
-    for (size_t i = 0; i < len && (p - buffer) < (maxLen - 3); i++) {
+    for (size_t i = 0; i < len && static_cast<size_t>(p - buffer) < (maxLen - 3); i++) {
       p += sprintf(p, "%02X", bytes[i]);
 
       if (i < (len - 1)) {

+ 1 - 1
lib/Helpers/TokenIterator.h

@@ -16,6 +16,6 @@ private:
   char* current;
   size_t length;
   char sep;
-  int i;
+  size_t i;
 };
 #endif

+ 1 - 0
lib/MiLight/CctPacketFormatter.cpp

@@ -184,6 +184,7 @@ MiLightStatus CctPacketFormatter::cctCommandToStatus(uint8_t command) {
     case CCT_GROUP_3_OFF:
     case CCT_GROUP_4_OFF:
     case CCT_ALL_OFF:
+    default:
       return OFF;
   }
 }

+ 7 - 7
lib/MiLight/FUT089PacketFormatter.cpp

@@ -28,15 +28,15 @@ void FUT089PacketFormatter::updateColorRaw(uint8_t value) {
   command(FUT089_COLOR, FUT089_COLOR_OFFSET + value);
 }
 
-// change the temperature (kelvin).  Note that temperature and saturation share the same command 
+// change the temperature (kelvin).  Note that temperature and saturation share the same command
 // number (7), and they change which they do based on the mode of the lamp (white vs. color mode).
 // To make this command work, we need to switch to white mode, make the change, and then flip
 // back to the original mode.
 void FUT089PacketFormatter::updateTemperature(uint8_t value) {
-  // look up our current mode 
+  // look up our current mode
   const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
   BulbMode originalBulbMode;
-  
+
   if (ourState != NULL) {
     originalBulbMode = ourState->getBulbMode();
 
@@ -55,15 +55,15 @@ void FUT089PacketFormatter::updateTemperature(uint8_t value) {
   }
 }
 
-// change the saturation.  Note that temperature and saturation share the same command 
+// change the saturation.  Note that temperature and saturation share the same command
 // number (7), and they change which they do based on the mode of the lamp (white vs. color mode).
 // Therefore, if we are not in color mode, we need to switch to color mode, make the change,
 // and switch back to the original mode.
 void FUT089PacketFormatter::updateSaturation(uint8_t value) {
-  // look up our current mode 
+  // look up our current mode
   const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
-  BulbMode originalBulbMode;
-  
+  BulbMode originalBulbMode = BulbMode::BULB_MODE_WHITE;
+
   if (ourState != NULL) {
     originalBulbMode = ourState->getBulbMode();
   }

+ 11 - 7
lib/MiLight/MiLightClient.cpp

@@ -10,8 +10,7 @@ MiLightClient::MiLightClient(
   GroupStateStore* stateStore,
   Settings* settings
 )
-  : baseResendCount(MILIGHT_DEFAULT_RESEND_COUNT),
-    currentRadio(NULL),
+  : currentRadio(NULL),
     currentRemote(NULL),
     numRadios(MiLightRadioConfig::NUM_CONFIGS),
     packetSentHandler(NULL),
@@ -19,7 +18,8 @@ MiLightClient::MiLightClient(
     updateEndHandler(NULL),
     stateStore(stateStore),
     settings(settings),
-    lastSend(0)
+    lastSend(0),
+    baseResendCount(MILIGHT_DEFAULT_RESEND_COUNT)
 {
   radios = new MiLightRadio*[numRadios];
 
@@ -36,7 +36,7 @@ void MiLightClient::begin() {
   switchRadio(static_cast<size_t>(0));
 
   // Little gross to do this here as it's relying on global state.  A better alternative
-  // would be to statically construct remote config factories which take in a stateStore 
+  // would be to statically construct remote config factories which take in a stateStore
   // and settings pointer.  The objects could then be initialized by calling the factory
   // in main.
   for (size_t i = 0; i < MiLightRemoteConfig::NUM_REMOTES; i++) {
@@ -66,9 +66,9 @@ MiLightRadio* MiLightClient::switchRadio(size_t radioIx) {
 }
 
 MiLightRadio* MiLightClient::switchRadio(const MiLightRemoteConfig* remoteConfig) {
-  MiLightRadio* radio;
+  MiLightRadio* radio = NULL;
 
-  for (int i = 0; i < numRadios; i++) {
+  for (size_t i = 0; i < numRadios; i++) {
     if (&this->radios[i]->config() == &remoteConfig->radioConfig) {
       radio = switchRadio(i);
       break;
@@ -518,7 +518,11 @@ void MiLightClient::updateResendCount() {
   long x = (millisSinceLastSend - settings->packetRepeatThrottleThreshold);
   long delta = x * throttleMultiplier;
 
-  this->currentResendCount = constrain(this->currentResendCount + delta, settings->packetRepeatMinimum, this->baseResendCount);
+  this->currentResendCount = constrain(
+    static_cast<size_t>(this->currentResendCount + delta),
+    settings->packetRepeatMinimum,
+    this->baseResendCount
+  );
   this->lastSend = now;
 }
 

+ 4 - 3
lib/MiLight/MiLightClient.h

@@ -90,16 +90,17 @@ protected:
   MiLightRadio* currentRadio;
   const MiLightRemoteConfig* currentRemote;
   const size_t numRadios;
-  GroupStateStore* stateStore;
-  const Settings* settings;
 
   PacketSentHandler packetSentHandler;
   EventHandler updateBeginHandler;
   EventHandler updateEndHandler;
 
+  GroupStateStore* stateStore;
+  const Settings* settings;
+
   // Used to track auto repeat limiting
   unsigned long lastSend;
-  int currentResendCount;
+  uint8_t currentResendCount;
   unsigned int baseResendCount;
 
   // This will be pre-computed, but is simply:

+ 3 - 1
lib/MiLight/PacketFormatter.cpp

@@ -124,6 +124,8 @@ void PacketFormatter::valueByStepFunction(StepFunction increase, StepFunction de
   } else if (targetValue > knownValue) {
     fn = increase;
     numCommands = (targetValue - knownValue);
+  } else {
+    return;
   }
 
   // Get to the desired value
@@ -161,7 +163,7 @@ void PacketFormatter::pushPacket() {
 }
 
 void PacketFormatter::format(uint8_t const* packet, char* buffer) {
-  for (int i = 0; i < packetLength; i++) {
+  for (size_t i = 0; i < packetLength; i++) {
     sprintf_P(buffer, "%02X ", packet[i]);
     buffer += 3;
   }

+ 4 - 4
lib/MiLight/PacketFormatter.h

@@ -90,17 +90,17 @@ public:
   size_t getPacketLength() const;
 
 protected:
-  uint8_t* currentPacket;
+  const MiLightRemoteType deviceType;
   size_t packetLength;
+  size_t numPackets;
+  uint8_t* currentPacket;
+  bool held;
   uint16_t deviceId;
   uint8_t groupId;
   uint8_t sequenceNum;
-  size_t numPackets;
-  bool held;
   PacketStream packetStream;
   GroupStateStore* stateStore = NULL;
   const Settings* settings = NULL;
-  const MiLightRemoteType deviceType;
 
   void pushPacket();
 

+ 7 - 7
lib/MiLight/RgbCctPacketFormatter.cpp

@@ -64,10 +64,10 @@ void RgbCctPacketFormatter::updateTemperature(uint8_t value) {
 // update saturation.  This only works when in Color mode, so if not in color we switch to color,
 // make the change, and switch back again.
 void RgbCctPacketFormatter::updateSaturation(uint8_t value) {
-   // look up our current mode 
+   // look up our current mode
   const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_RGB_CCT);
-  BulbMode originalBulbMode;
-  
+  BulbMode originalBulbMode = BulbMode::BULB_MODE_WHITE;
+
   if (ourState != NULL) {
     originalBulbMode = ourState->getBulbMode();
 
@@ -90,11 +90,11 @@ void RgbCctPacketFormatter::updateSaturation(uint8_t value) {
 
 void RgbCctPacketFormatter::updateColorWhite() {
   // there is no direct white command, so let's look up our prior temperature and set that, which
-  // causes the bulb to go white 
+  // causes the bulb to go white
   const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_RGB_CCT);
-  uint8_t value = 
-    ourState == NULL 
-      ? 0 
+  uint8_t value =
+    ourState == NULL
+      ? 0
       : V2PacketFormatter::tov2scale(ourState->getKelvin(), RGB_CCT_KELVIN_REMOTE_END, 2);
 
   // issue command to set kelvin to prior value, which will drive to white

+ 2 - 2
lib/MiLight/V2PacketFormatter.cpp

@@ -62,7 +62,7 @@ void V2PacketFormatter::finalizePacket(uint8_t* packet) {
 
 void V2PacketFormatter::format(uint8_t const* packet, char* buffer) {
   buffer += sprintf_P(buffer, PSTR("Raw packet: "));
-  for (int i = 0; i < packetLength; i++) {
+  for (size_t i = 0; i < packetLength; i++) {
     buffer += sprintf_P(buffer, PSTR("%02X "), packet[i]);
   }
 
@@ -106,7 +106,7 @@ void V2PacketFormatter::switchMode(const GroupState& currentState, BulbMode desi
       Serial.printf_P(PSTR("V2PacketFormatter::switchMode: Request to switch to unknown mode %d\n"), desiredMode);
       break;
   }
-  
+
 }
 
 uint8_t V2PacketFormatter::tov2scale(uint8_t value, uint8_t endValue, uint8_t interval, bool reverse) {

+ 52 - 20
lib/MiLightState/GroupState.cpp

@@ -3,6 +3,13 @@
 #include <MiLightRemoteConfig.h>
 #include <RGBConverter.h>
 
+static const char* BULB_MODE_NAMES[] = {
+  "white",
+  "color",
+  "scene",
+  "night"
+};
+
 const BulbId DEFAULT_BULB_ID;
 static const GroupStateField ALL_PHYSICAL_FIELDS[] = {
   GroupStateField::BRIGHTNESS,
@@ -33,6 +40,10 @@ const GroupState& GroupState::defaultState(MiLightRemoteType remoteType) {
     case REMOTE_TYPE_CCT:
       state.setBulbMode(BULB_MODE_WHITE);
       break;
+
+    default:
+      // No modifications needed
+      break;
   }
 
   return state;
@@ -106,6 +117,7 @@ void GroupState::initFields() {
 GroupState& GroupState::operator=(const GroupState& other) {
   memcpy(state.rawData, other.state.rawData, DATA_LONGS * sizeof(uint32_t));
   scratchpad.rawData = other.scratchpad.rawData;
+  return *this;
 }
 
 GroupState::GroupState()
@@ -206,6 +218,10 @@ bool GroupState::clearField(GroupStateField field) {
       // Clear brightness as well
       clearedAny = clearBrightness() || clearedAny;
       break;
+
+    default:
+      Serial.printf_P(PSTR("Attempted to clear unknown field: %d\n"), static_cast<uint8_t>(field));
+      break;
   }
 
   return clearedAny;
@@ -242,11 +258,12 @@ bool GroupState::isSetField(GroupStateField field) const {
       return isSetKelvin();
     case GroupStateField::BULB_MODE:
       return isSetBulbMode();
+    default:
+      Serial.print(F("WARNING: tried to check if unknown field was set: "));
+      Serial.println(static_cast<unsigned int>(field));
+      break;
   }
 
-  Serial.print(F("WARNING: tried to check if unknown field was set: "));
-  Serial.println(static_cast<unsigned int>(field));
-
   return false;
 }
 
@@ -256,11 +273,12 @@ bool GroupState::isSetScratchField(GroupStateField field) const {
       return scratchpad.fields._isSetBrightnessScratch;
     case GroupStateField::KELVIN:
       return scratchpad.fields._isSetKelvinScratch;
+    default:
+      Serial.print(F("WARNING: tried to check if unknown scratch field was set: "));
+      Serial.println(static_cast<unsigned int>(field));
+      break;
   }
 
-  Serial.print(F("WARNING: tried to check if unknown scratch field was set: "));
-  Serial.println(static_cast<unsigned int>(field));
-
   return false;
 }
 
@@ -281,11 +299,12 @@ uint16_t GroupState::getFieldValue(GroupStateField field) const {
       return getKelvin();
     case GroupStateField::BULB_MODE:
       return getBulbMode();
+    default:
+      Serial.print(F("WARNING: tried to fetch value for unknown field: "));
+      Serial.println(static_cast<unsigned int>(field));
+      break;
   }
 
-  Serial.print(F("WARNING: tried to fetch value for unknown field: "));
-  Serial.println(static_cast<unsigned int>(field));
-
   return 0;
 }
 
@@ -295,11 +314,12 @@ uint16_t GroupState::getScratchFieldValue(GroupStateField field) const {
       return scratchpad.fields._brightnessScratch;
     case GroupStateField::KELVIN:
       return scratchpad.fields._kelvinScratch;
+    default:
+      Serial.print(F("WARNING: tried to fetch value for unknown scratch field: "));
+      Serial.println(static_cast<unsigned int>(field));
+      break;
   }
 
-  Serial.print(F("WARNING: tried to fetch value for unknown scratch field: "));
-  Serial.println(static_cast<unsigned int>(field));
-
   return 0;
 }
 
@@ -531,8 +551,6 @@ bool GroupState::setMireds(uint16_t mireds) {
 
 bool GroupState::isSetBulbMode() const { return state.fields._isSetBulbMode; }
 BulbMode GroupState::getBulbMode() const {
-  BulbMode mode;
-
   // Night mode is a transient state.  When power is toggled, the bulb returns
   // to the state it was last in.  To handle this case, night mode state is
   // stored separately.
@@ -578,11 +596,19 @@ bool GroupState::isDirty() const { return state.fields._dirty; }
 inline bool GroupState::setDirty() {
   state.fields._dirty = 1;
   state.fields._mqttDirty = 1;
+
+  return true;
+}
+bool GroupState::clearDirty() {
+  state.fields._dirty = 0;
+  return true;
 }
-bool GroupState::clearDirty() { state.fields._dirty = 0; }
 
 bool GroupState::isMqttDirty() const { return state.fields._mqttDirty; }
-bool GroupState::clearMqttDirty() { state.fields._mqttDirty = 0; }
+bool GroupState::clearMqttDirty() {
+  state.fields._mqttDirty = 0;
+  return true;
+}
 
 void GroupState::load(Stream& stream) {
   for (size_t i = 0; i < DATA_LONGS; i++) {
@@ -672,7 +698,7 @@ bool GroupState::clearNonMatchingFields(const GroupState& other) {
   return clearedAny;
 }
 
-bool GroupState::patch(const GroupState& other) {
+void GroupState::patch(const GroupState& other) {
 #ifdef STATE_DEBUG
   other.debugState("Patching existing state with: ");
   Serial.println();
@@ -895,11 +921,17 @@ void GroupState::applyField(JsonObject& partialState, const BulbId& bulbId, Grou
         break;
 
       case GroupStateField::DEVICE_TYPE:
-        const MiLightRemoteConfig* remoteConfig = MiLightRemoteConfig::fromType(bulbId.deviceType);
-        if (remoteConfig) {
-          partialState["device_type"] = remoteConfig->name;
+        {
+          const MiLightRemoteConfig* remoteConfig = MiLightRemoteConfig::fromType(bulbId.deviceType);
+          if (remoteConfig) {
+            partialState["device_type"] = remoteConfig->name;
+          }
         }
         break;
+
+      default:
+        Serial.printf_P(PSTR("Tried to apply unknown field: %d\n"), static_cast<uint8_t>(field));
+        break;
     }
   }
 }

+ 9 - 17
lib/MiLightState/GroupState.h

@@ -31,17 +31,10 @@ enum BulbMode {
 };
 
 enum class IncrementDirection : unsigned {
-  INCREASE = 1, 
+  INCREASE = 1,
   DECREASE = -1U
 };
 
-static const char* BULB_MODE_NAMES[] = {
-  "white",
-  "color",
-  "scene",
-  "night"
-};
-
 class GroupState {
 public:
 
@@ -126,11 +119,10 @@ public:
   // than the provided group state.
   bool clearNonMatchingFields(const GroupState& other);
 
-  // Patches this state with ONLY the set fields in the other. Returns 
-  // true if there were any changes.
-  bool patch(const GroupState& other);
+  // Patches this state with ONLY the set fields in the other.
+  void patch(const GroupState& other);
 
-  // Patches this state with the fields defined in the JSON state.  Returns 
+  // Patches this state with the fields defined in the JSON state.  Returns
   // true if there were any changes.
   bool patch(const JsonObject& state);
 
@@ -142,10 +134,10 @@ public:
   void applyState(JsonObject& state, const BulbId& bulbId, GroupStateField* fields, size_t numFields) const;
 
   // Attempt to keep track of increment commands in such a way that we can
-  // know what state it's in.  When we get an increment command (like "increase 
+  // know what state it's in.  When we get an increment command (like "increase
   // brightness"):
-  //   1. If there is no value in the scratch state: assume real state is in 
-  //      the furthest value from the direction of the command.  For example, 
+  //   1. If there is no value in the scratch state: assume real state is in
+  //      the furthest value from the direction of the command.  For example,
   //      if we get "increase," assume the value was 0.
   //   2. If there is a value in the scratch state, apply the command to it.
   //      For example, if we get "decrease," subtract 1 from the scratch.
@@ -153,7 +145,7 @@ public:
   //      persistent field to that value
   //   4. If there is already a known value for the state, apply it rather
   //      than messing with scratch state.
-  // 
+  //
   // returns true if a (real, not scratch) state change was made
   bool applyIncrementCommand(GroupStateField field, IncrementDirection dir);
 
@@ -201,7 +193,7 @@ private:
   union TransientData {
     uint16_t rawData;
     struct Fields {
-      uint16_t 
+      uint16_t
         _isSetKelvinScratch     : 1,
         _kelvinScratch          : 7,
         _isSetBrightnessScratch : 1,

+ 2 - 0
lib/Radio/LT8900MiLightRadio.cpp

@@ -442,6 +442,8 @@ bool LT8900MiLightRadio::sendPacket(uint8_t *data, size_t packetSize, byte byCha
 
     return true;
   }
+
+  return false;
 }
 
 const MiLightRadioConfig& LT8900MiLightRadio::config() {

+ 4 - 3
lib/Radio/MiLightRadioFactory.h

@@ -15,6 +15,7 @@
 class MiLightRadioFactory {
 public:
 
+  virtual ~MiLightRadioFactory() { };
   virtual MiLightRadio* create(const MiLightRadioConfig& config) = 0;
 
   static MiLightRadioFactory* fromSettings(const Settings& settings);
@@ -25,9 +26,9 @@ class NRF24Factory : public MiLightRadioFactory {
 public:
 
   NRF24Factory(
-    uint8_t cePin, 
-    uint8_t csnPin, 
-    RF24PowerLevel rF24PowerLevel, 
+    uint8_t cePin,
+    uint8_t csnPin,
+    RF24PowerLevel rF24PowerLevel,
     const std::vector<RF24Channel>& channels,
     RF24Channel listenChannel
   );

+ 6 - 6
lib/Radio/NRF24MiLightRadio.cpp

@@ -6,16 +6,16 @@
 #define PACKET_ID(packet, packet_length) ( (packet[1] << 8) | packet[packet_length - 1] )
 
 NRF24MiLightRadio::NRF24MiLightRadio(
-  RF24& rf24, 
-  const MiLightRadioConfig& config, 
+  RF24& rf24,
+  const MiLightRadioConfig& config,
   const std::vector<RF24Channel>& channels,
   RF24Channel listenChannel
 )
-  : _pl1167(PL1167_nRF24(rf24)),
-    channels(channels),
+  : channels(channels),
     listenChannelIx(static_cast<size_t>(listenChannel)),
-    _waiting(false),
-    _config(config)
+    _pl1167(PL1167_nRF24(rf24)),
+    _config(config),
+    _waiting(false)
 { }
 
 int NRF24MiLightRadio::begin() {

+ 8 - 8
lib/Settings/Settings.h

@@ -92,7 +92,6 @@ public:
     packetRepeats(50),
     httpRepeatFactor(1),
     listenRepeats(3),
-    _autoRestartPeriod(0),
     discoveryPort(48899),
     stateFlushInterval(10000),
     mqttStateRateLimit(500),
@@ -110,7 +109,8 @@ public:
     hostname("milight-hub"),
     rf24PowerLevel(RF24PowerLevelHelpers::defaultValue()),
     rf24Channels(RF24ChannelHelpers::allValues()),
-    rf24ListenChannel(RF24Channel::RF24_LOW)
+    rf24ListenChannel(RF24Channel::RF24_LOW),
+    _autoRestartPeriod(0)
   {
     if (groupStateFields == NULL) {
       numGroupStateFields = size(DEFAULT_GROUP_STATE_FIELDS);
@@ -155,10 +155,12 @@ public:
   RadioInterfaceType radioInterfaceType;
   uint16_t *deviceIds;
   GatewayConfig **gatewayConfigs;
-  size_t numGatewayConfigs;
   size_t numDeviceIds;
+  size_t numGatewayConfigs;
   size_t packetRepeats;
   size_t httpRepeatFactor;
+  uint8_t listenRepeats;
+  uint16_t discoveryPort;
   String _mqttServer;
   String mqttUsername;
   String mqttPassword;
@@ -168,15 +170,13 @@ public:
   String mqttLwtTopic;
   String mqttLwtMessage;
   String mqttBirthTopic;
-  GroupStateField *groupStateFields;
-  size_t numGroupStateFields;
-  uint16_t discoveryPort;
-  uint8_t listenRepeats;
   size_t stateFlushInterval;
   size_t mqttStateRateLimit;
-  size_t packetRepeatThrottleSensitivity;
   size_t packetRepeatThrottleThreshold;
+  size_t packetRepeatThrottleSensitivity;
   size_t packetRepeatMinimum;
+  GroupStateField *groupStateFields;
+  size_t numGroupStateFields;
   bool enableAutomaticModeSwitching;
   LEDStatus::LEDMode ledModeWifiConfig;
   LEDStatus::LEDMode ledModeWifiFailed;

+ 2 - 2
lib/Settings/StringStream.h

@@ -1,7 +1,7 @@
 /*
  * Adapated from https://gist.github.com/cmaglie/5883185
  */
- 
+
 #ifndef _STRING_STREAM_H_INCLUDED_
 #define _STRING_STREAM_H_INCLUDED_
 
@@ -18,7 +18,7 @@ public:
     virtual int peek() { return position < string.length() ? string[position] : -1; }
     virtual void flush() { };
     // Print methods
-    virtual size_t write(uint8_t c) { string += (char)c; };
+    virtual size_t write(uint8_t c) { string += (char)c; return 1; };
 
 private:
     String &string;

+ 21 - 0
lib/Types/GroupStateField.cpp

@@ -1,6 +1,27 @@
 #include <GroupStateField.h>
 #include <Size.h>
 
+static const char* STATE_NAMES[] = {
+  "unknown",
+  "state",
+  "status",
+  "brightness",
+  "level",
+  "hue",
+  "saturation",
+  "color",
+  "mode",
+  "kelvin",
+  "color_temp",
+  "bulb_mode",
+  "computed_color",
+  "effect",
+  "device_id",
+  "group_id",
+  "device_type",
+  "oh_color"
+};
+
 GroupStateField GroupStateFieldHelpers::getFieldByName(const char* name) {
   for (size_t i = 0; i < size(STATE_NAMES); i++) {
     if (0 == strcmp(name, STATE_NAMES[i])) {

+ 0 - 21
lib/Types/GroupStateField.h

@@ -1,27 +1,6 @@
 #ifndef _GROUP_STATE_FIELDS_H
 #define _GROUP_STATE_FIELDS_H
 
-static const char* STATE_NAMES[] = {
-  "unknown",
-  "state",
-  "status",
-  "brightness",
-  "level",
-  "hue",
-  "saturation",
-  "color",
-  "mode",
-  "kelvin",
-  "color_temp",
-  "bulb_mode",
-  "computed_color",
-  "effect",
-  "device_id",
-  "group_id",
-  "device_type",
-  "oh_color"
-};
-
 enum class GroupStateField {
   UNKNOWN,
   STATE,

+ 6 - 0
lib/Types/RF24Channel.cpp

@@ -1,6 +1,12 @@
 #include <Size.h>
 #include <RF24Channel.h>
 
+static const char* RF24_CHANNEL_NAMES[] = {
+  "LOW",
+  "MID",
+  "HIGH"
+};
+
 String RF24ChannelHelpers::nameFromValue(const RF24Channel& value) {
   const size_t ix = static_cast<size_t>(value);
 

+ 0 - 6
lib/Types/RF24Channel.h

@@ -4,12 +4,6 @@
 #ifndef _RF24_CHANNELS_H
 #define _RF24_CHANNELS_H
 
-static const char* RF24_CHANNEL_NAMES[] = {
-  "LOW",
-  "MID",
-  "HIGH"
-};
-
 enum class RF24Channel {
   RF24_LOW = 0,
   RF24_MID = 1,

+ 7 - 0
lib/Types/RF24PowerLevel.cpp

@@ -1,6 +1,13 @@
 #include <RF24PowerLevel.h>
 #include <Size.h>
 
+static const char* RF24_POWER_LEVEL_NAMES[] = {
+  "MIN",
+  "LOW",
+  "HIGH",
+  "MAX"
+};
+
 String RF24PowerLevelHelpers::nameFromValue(const RF24PowerLevel& value) {
   const size_t ix = static_cast<size_t>(value);
 

+ 0 - 7
lib/Types/RF24PowerLevel.h

@@ -4,13 +4,6 @@
 #ifndef _RF24_POWER_LEVEL_H
 #define _RF24_POWER_LEVEL_H
 
-static const char* RF24_POWER_LEVEL_NAMES[] = {
-  "MIN",
-  "LOW",
-  "HIGH",
-  "MAX"
-};
-
 enum class RF24PowerLevel {
   RF24_MIN  = RF24_PA_MIN,  // -18 dBm
   RF24_LOW  = RF24_PA_LOW,  // -12 dBm

+ 1 - 0
lib/Udp/MiLightDiscoveryServer.cpp

@@ -16,6 +16,7 @@ MiLightDiscoveryServer::MiLightDiscoveryServer(MiLightDiscoveryServer& other)
 MiLightDiscoveryServer& MiLightDiscoveryServer::operator=(MiLightDiscoveryServer other) {
   this->settings = other.settings;
   this->socket = other.socket;
+  return *this;
 }
 
 MiLightDiscoveryServer::~MiLightDiscoveryServer() {

+ 7 - 7
lib/Udp/MiLightUdpServer.h

@@ -5,25 +5,25 @@
 // This protocol is documented here:
 // http://www.limitlessled.com/dev/
 
-#define MILIGHT_PACKET_BUFFER_SIZE 30 
+#define MILIGHT_PACKET_BUFFER_SIZE 30
 
 // Uncomment to enable Serial printing of packets
 // #define MILIGHT_UDP_DEBUG
 
 #ifndef _MILIGHT_UDP_SERVER
-#define _MILIGHT_UDP_SERVER 
+#define _MILIGHT_UDP_SERVER
 
 class MiLightUdpServer {
 public:
   MiLightUdpServer(MiLightClient*& client, uint16_t port, uint16_t deviceId);
-  ~MiLightUdpServer();
-    
+  virtual ~MiLightUdpServer();
+
   void stop();
   void begin();
   void handleClient();
-  
+
   static MiLightUdpServer* fromVersion(uint8_t version, MiLightClient*&, uint16_t port, uint16_t deviceId);
-    
+
 protected:
   WiFiUDP socket;
   MiLightClient*& client;
@@ -32,7 +32,7 @@ protected:
   uint8_t lastGroup;
   uint8_t packetBuffer[MILIGHT_PACKET_BUFFER_SIZE];
   uint8_t responseBuffer[MILIGHT_PACKET_BUFFER_SIZE];
-  
+
   // Should return size of the response packet
   virtual void handlePacket(uint8_t* packet, size_t packetSize) = 0;
 };

+ 4 - 2
lib/Udp/V5MiLightUdpServer.cpp

@@ -29,8 +29,10 @@ void V5MiLightUdpServer::handleCommand(uint8_t command, uint8_t commandArg) {
     this->lastGroup = groupId;
   // Set night_mode for RGBW
  } else if (command == UDP_RGBW_GROUP_ALL_NIGHT || command == UDP_RGBW_GROUP_1_NIGHT || command == UDP_RGBW_GROUP_2_NIGHT || command == UDP_RGBW_GROUP_3_NIGHT || command == UDP_RGBW_GROUP_4_NIGHT) {
-    const uint8_t groupId = (command - UDP_RGBW_GROUP_1_NIGHT + 2)/2;
-    if (command == UDP_RGBW_GROUP_ALL_NIGHT) const uint8_t groupId = 0;
+    uint8_t groupId = (command - UDP_RGBW_GROUP_1_NIGHT + 2)/2;
+    if (command == UDP_RGBW_GROUP_ALL_NIGHT) {
+      groupId = 0;
+    }
 
     client->prepare(&FUT096Config, deviceId, groupId);
     client->enableNightMode();

+ 2 - 2
lib/Udp/V6MiLightUdpServer.h

@@ -63,9 +63,9 @@ protected:
 
   static uint8_t OPEN_COMMAND_RESPONSE[];
 
-  V6Session* firstSession;
-  size_t numSessions;
   uint16_t sessionId;
+  size_t numSessions;
+  V6Session* firstSession;
 
   uint16_t beginSession();
   bool sendResponse(uint16_t sessionId, uint8_t* responseBuffer, size_t responseSize);

+ 1 - 2
lib/Udp/V6RgbCommandHandler.cpp

@@ -4,8 +4,7 @@ bool V6RgbCommandHandler::handlePreset(
     MiLightClient* client,
     uint8_t commandLsb,
     uint32_t commandArg)
-{
-}
+{ return true; }
 
 bool V6RgbCommandHandler::handleCommand(
     MiLightClient* client,

+ 4 - 2
lib/WebServer/MiLightHttpServer.cpp

@@ -269,7 +269,6 @@ void MiLightHttpServer::handleFirmwareUpload() {
 
 
 void MiLightHttpServer::handleListenGateway(const UrlTokenBindings* bindings) {
-  bool available = false;
   bool listenAll = bindings == NULL;
   size_t configIx = 0;
   const MiLightRadioConfig* radioConfig = NULL;
@@ -350,7 +349,6 @@ void MiLightHttpServer::handleGetGroup(const UrlTokenBindings* urlBindings) {
   }
 
   BulbId bulbId(parseInt<uint16_t>(_deviceId), _groupId, _remoteType->type);
-  GroupState* state = stateStore->get(bulbId);
   sendGroupState(bulbId, stateStore->get(bulbId));
 }
 
@@ -481,6 +479,10 @@ void MiLightHttpServer::handleWsEvent(uint8_t num, WStype_t type, uint8_t *paylo
     case WStype_CONNECTED:
       numWsClients++;
       break;
+
+    default:
+      Serial.printf_P(PSTR("Unhandled websocket event: %d\n"), static_cast<uint8_t>(type));
+      break;
   }
 }
 

+ 2 - 2
lib/WebServer/MiLightHttpServer.h

@@ -67,11 +67,11 @@ protected:
 
   WebServer server;
   WebSocketsServer wsServer;
-  Settings& settings;
+  size_t numWsClients;
   MiLightClient*& milightClient;
+  Settings& settings;
   GroupStateStore*& stateStore;
   SettingsSavedHandler settingsSavedHandler;
-  size_t numWsClients;
   ESP8266WebServer::THandlerFunction _handleRootPage;
 
 };

+ 6 - 4
lib/WebServer/PatternHandler.cpp

@@ -4,10 +4,10 @@ PatternHandler::PatternHandler(
     const String& pattern,
     const HTTPMethod method,
     const PatternHandler::TPatternHandlerFn fn)
-  : method(method),
-    fn(fn),
-    _pattern(new char[pattern.length() + 1]),
-    patternTokens(NULL)
+  : _pattern(new char[pattern.length() + 1]),
+    patternTokens(NULL),
+    method(method),
+    fn(fn)
 {
   strcpy(_pattern, pattern.c_str());
   patternTokens = new TokenIterator(_pattern, pattern.length(), '/');
@@ -59,4 +59,6 @@ bool PatternHandler::handle(ESP8266WebServer& server, HTTPMethod requestMethod,
 
   UrlTokenBindings bindings(*patternTokens, requestTokens);
   fn(&bindings);
+
+  return true;
 }