diff --git a/app/jobs/mqtt_forwarding_job.rb b/app/jobs/mqtt_forwarding_job.rb index e155a91f..7798001a 100644 --- a/app/jobs/mqtt_forwarding_job.rb +++ b/app/jobs/mqtt_forwarding_job.rb @@ -17,7 +17,7 @@ def perform(device_id, data) private def payload_for(device, readings) - Presenters.present(device, device.owner, nil, readings: readings) + Presenters.present(device, device.owner, nil, readings: readings).to_json end def mqtt_client diff --git a/app/lib/presenters/component_presenter.rb b/app/lib/presenters/component_presenter.rb index 29003c77..daec1821 100644 --- a/app/lib/presenters/component_presenter.rb +++ b/app/lib/presenters/component_presenter.rb @@ -37,10 +37,7 @@ def readings def format_reading(reading) timestamp = reading[""] value = reading[component.sensor_id.to_s] - raw_value = reading["#{component.sensor_id}_raw"] - if value || raw_value - { timestamp: timestamp, value: value, raw_value: raw_value }.compact - end + { timestamp: timestamp, value: value } if value end end end diff --git a/spec/jobs/mqtt_forwarding_job_spec.rb b/spec/jobs/mqtt_forwarding_job_spec.rb index 81c8960e..24086520 100644 --- a/spec/jobs/mqtt_forwarding_job_spec.rb +++ b/spec/jobs/mqtt_forwarding_job_spec.rb @@ -18,6 +18,12 @@ double(:device_json) } + let(:device_representation) { + double(:device_representation).tap do |device_representation| + allow(device_representation).to receive(:to_json).and_return(device_json) + end + } + let(:forwarder) { double(:forwarder).tap do |forwarder| allow(forwarder).to receive(:forward_readings) @@ -26,7 +32,7 @@ before do allow(MQTTClientFactory).to receive(:create_client).and_return(mqtt_client) - allow(Presenters).to receive(:present).and_return(device_json) + allow(Presenters).to receive(:present).and_return(device_representation) allow(MQTTForwarder).to receive(:new).and_return(forwarder) allow_any_instance_of(Device).to receive(:forwarding_token).and_return(forwarding_token) end diff --git a/spec/presenters/component_presenter_spec.rb b/spec/presenters/component_presenter_spec.rb index 924032a0..fb0a74bd 100644 --- a/spec/presenters/component_presenter_spec.rb +++ b/spec/presenters/component_presenter_spec.rb @@ -65,7 +65,6 @@ context "when readings are supplied" do let(:reading_timestamp) { Time.now - 6.hours } let(:reading_value) { 1234.1 } - let(:reading_raw_value) { 2468.1 } let(:options) { { readings: [ @@ -73,16 +72,15 @@ { "" => reading_timestamp, "#{component.sensor_id}" => reading_value, - "#{component.sensor_id}_raw" => reading_raw_value, "#{component.sensor_id + 1}" => 54321.0 } ] } } - it "returns the readings formatted with timestamp, value and raw_value" do + it "returns the readings formatted with timestamp and value" do expect(presenter.as_json[:readings]).to eq([ - { timestamp: reading_timestamp, value: reading_value, raw_value: reading_raw_value } + { timestamp: reading_timestamp, value: reading_value } ]) end end