BulbStateUpdater.h 733 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Enqueues updated bulb states and flushes them at the configured interval.
  3. */
  4. #include <stddef.h>
  5. #include <MqttClient.h>
  6. #include <CircularBuffer.h>
  7. #include <Settings.h>
  8. #ifndef BULB_STATE_UPDATER
  9. #define BULB_STATE_UPDATER
  10. class BulbStateUpdater {
  11. public:
  12. BulbStateUpdater(Settings& settings, MqttClient& mqttClient, GroupStateStore& stateStore);
  13. void enqueueUpdate(GroupId groupId, GroupState& groupState);
  14. void loop();
  15. private:
  16. Settings& settings;
  17. MqttClient& mqttClient;
  18. GroupStateStore& stateStore;
  19. CircularBuffer<GroupId, MILIGHT_MAX_STALE_MQTT_GROUPS> staleGroups;
  20. unsigned long lastFlush;
  21. inline void flushGroup(GroupId groupId, GroupState& state);
  22. inline bool canFlush() const;
  23. };
  24. #endif