ソースを参照

Add setting for simple MQTT client status messages, and test to ensure that it is persisted

Christopher Mullins 6 年 前
コミット
c80346f2e1
共有3 個のファイルを変更した17 個の追加0 個の削除を含む
  1. 2 0
      lib/Settings/Settings.cpp
  2. 2 0
      lib/Settings/Settings.h
  3. 13 0
      test/remote/spec/settings_spec.rb

+ 2 - 0
lib/Settings/Settings.cpp

@@ -83,6 +83,7 @@ void Settings::patch(JsonObject parsedSettings) {
   this->setIfPresent(parsedSettings, "mqtt_update_topic_pattern", mqttUpdateTopicPattern);
   this->setIfPresent(parsedSettings, "mqtt_state_topic_pattern", mqttStateTopicPattern);
   this->setIfPresent(parsedSettings, "mqtt_client_status_topic", mqttClientStatusTopic);
+  this->setIfPresent(parsedSettings, "simple_mqtt_client_status", simpleMqttClientStatus);
   this->setIfPresent(parsedSettings, "discovery_port", discoveryPort);
   this->setIfPresent(parsedSettings, "listen_repeats", listenRepeats);
   this->setIfPresent(parsedSettings, "state_flush_interval", stateFlushInterval);
@@ -205,6 +206,7 @@ void Settings::serialize(Print& stream, const bool prettyPrint) {
   root["mqtt_update_topic_pattern"] = this->mqttUpdateTopicPattern;
   root["mqtt_state_topic_pattern"] = this->mqttStateTopicPattern;
   root["mqtt_client_status_topic"] = this->mqttClientStatusTopic;
+  root["simple_mqtt_client_status"] = this->simpleMqttClientStatus;
   root["discovery_port"] = this->discoveryPort;
   root["listen_repeats"] = this->listenRepeats;
   root["state_flush_interval"] = this->stateFlushInterval;

+ 2 - 0
lib/Settings/Settings.h

@@ -90,6 +90,7 @@ public:
     httpRepeatFactor(1),
     listenRepeats(3),
     discoveryPort(48899),
+    simpleMqttClientStatus(false),
     stateFlushInterval(10000),
     mqttStateRateLimit(500),
     packetRepeatThrottleThreshold(200),
@@ -150,6 +151,7 @@ public:
   String mqttUpdateTopicPattern;
   String mqttStateTopicPattern;
   String mqttClientStatusTopic;
+  bool simpleMqttClientStatus;
   size_t stateFlushInterval;
   size_t mqttStateRateLimit;
   size_t packetRepeatThrottleThreshold;

+ 13 - 0
test/remote/spec/settings_spec.rb

@@ -23,6 +23,19 @@ RSpec.describe 'Settings' do
     @client.clear_auth!
   end
 
+  context 'keys' do
+    it 'should persist known settings keys' do
+      {
+        'simple_mqtt_client_status' => [true, false]
+      }.each do |key, values|
+        values.each do |v|
+          @client.patch_settings({key => v})
+          expect(@client.get('/settings')[key]).to eq(v)
+        end
+      end
+    end
+  end
+
   context 'POST settings file' do
     it 'should clobber patched settings' do
       file = Tempfile.new('espmh-settings.json')