Quellcode durchsuchen

return default state instead of NULL

Chris Mullins vor 8 Jahren
Ursprung
Commit
a80dc6d848

+ 3 - 1
lib/MiLight/PacketFormatter.h

@@ -3,6 +3,8 @@
 #include <functional>
 #include <MiLightButtons.h>
 #include <ArduinoJson.h>
+#include <GroupState.h>
+#include <GroupStateStore.h>
 
 #ifndef _PACKET_FORMATTER_H
 #define _PACKET_FORMATTER_H
@@ -69,7 +71,7 @@ public:
   virtual void prepare(uint16_t deviceId, uint8_t groupId);
   virtual void format(uint8_t const* packet, char* buffer);
 
-  virtual void parsePacket(const uint8_t* packet, JsonObject& result);
+  virtual const GroupState* parsePacket(const uint8_t* packet, GroupStateStore* stateStore);
 
   static void formatV1Packet(uint8_t const* packet, char* buffer);
 

+ 2 - 0
lib/MiLightState/GroupState.h

@@ -55,6 +55,8 @@ public:
   BulbMode getBulbMode();
   void setBulbMode(BulbMode mode);
 
+  static const GroupState DEFAULT_STATE;
+
 private:
   uint32_t
     _on         : 1,

+ 7 - 1
lib/MiLightState/GroupStateCache.cpp

@@ -5,7 +5,13 @@ GroupStateCache::GroupStateCache(const size_t maxSize)
 { }
 
 const GroupState* GroupStateCache::get(const GroupId& id) {
-  return getInternal(id);
+  GroupState* state = getInternal(id);
+
+  if (state == NULL) {
+    return &GroupState::DEFAULT_STATE;
+  } else {
+    return state;
+  }
 }
 
 void GroupStateCache::set(const GroupId& id, const GroupState& state) {