/** * Enqueues updated bulb states and flushes them at the configured interval. */ #include #include #include #include #ifndef BULB_STATE_UPDATER #define BULB_STATE_UPDATER class BulbStateUpdater { public: BulbStateUpdater(Settings& settings, MqttClient& mqttClient, GroupStateStore& stateStore); void enqueueUpdate(BulbId bulbId, GroupState& groupState); void loop(); void enable(); void disable(); private: Settings& settings; MqttClient& mqttClient; GroupStateStore& stateStore; CircularBuffer staleGroups; unsigned long lastFlush; unsigned long lastQueue; bool enabled; inline void flushGroup(BulbId bulbId, GroupState& state); inline bool canFlush() const; }; #endif