mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Fix owntracks params
This commit is contained in:
parent
3b5a2713fc
commit
5c16cc6dca
5 changed files with 82 additions and 31 deletions
|
|
@ -22,16 +22,12 @@ class OwnTracks::ExportParser
|
|||
user_id:
|
||||
)
|
||||
|
||||
Point.create(
|
||||
latitude: point_data[:latitude],
|
||||
longitude: point_data[:longitude],
|
||||
timestamp: point_data[:timestamp],
|
||||
raw_data: point_data[:raw_data],
|
||||
topic: point_data[:topic],
|
||||
tracker_id: point_data[:tracker_id],
|
||||
import_id: import.id,
|
||||
user_id:
|
||||
)
|
||||
point = Point.new(point_data).tap do |p|
|
||||
p.user_id = user_id
|
||||
p.import_id = import.id
|
||||
end
|
||||
|
||||
point.save
|
||||
|
||||
points += 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,18 +36,18 @@ class OwnTracks::Params
|
|||
def battery_status
|
||||
return 'unknown' if params[:bs].nil?
|
||||
|
||||
case params[:bs]
|
||||
when 'u' then 'unplugged'
|
||||
when 'c' then 'charging'
|
||||
when 'f' then 'full'
|
||||
case params[:bs].to_i
|
||||
when 1 then 'unplugged'
|
||||
when 2 then 'charging'
|
||||
when 3 then 'full'
|
||||
else 'unknown'
|
||||
end
|
||||
end
|
||||
|
||||
def trigger
|
||||
return 'unknown' if params[:m].nil?
|
||||
return 'unknown' if params[:t].nil?
|
||||
|
||||
case params[:m]
|
||||
case params[:t]
|
||||
when 'p' then 'background_event'
|
||||
when 'c' then 'circular_region_event'
|
||||
when 'b' then 'beacon_event'
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ class ReverseGeocoding::FetchData
|
|||
private
|
||||
|
||||
def reverse_geocoded?
|
||||
point.city.present? && point.country.present? || point.geodata.present?
|
||||
point.geodata.present?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,6 +13,59 @@ RSpec.describe OwnTracks::ExportParser do
|
|||
it 'creates points' do
|
||||
expect { parser }.to change { Point.count }.by(9)
|
||||
end
|
||||
|
||||
it 'correctly writes attributes' do
|
||||
parser
|
||||
|
||||
expect(Point.first.attributes).to include(
|
||||
'latitude' => 40.7128,
|
||||
'longitude' => -74.006,
|
||||
'battery_status' => 'charging',
|
||||
'battery' => 85,
|
||||
'ping' => nil,
|
||||
'altitude' => 41,
|
||||
'accuracy' => 8,
|
||||
'vertical_accuracy' => 3,
|
||||
'velocity' => nil,
|
||||
'connection' => 'wifi',
|
||||
'ssid' => 'Home Wifi',
|
||||
'bssid' => 'b0:f2:8:45:94:33',
|
||||
'trigger' => 'background_event',
|
||||
'tracker_id' => 'RO',
|
||||
'timestamp' => 1_706_965_203,
|
||||
'inrids' => ['5f1d1b'],
|
||||
'in_regions' => ['home'],
|
||||
'topic' => 'owntracks/test/iPhone 12 Pro',
|
||||
'visit_id' => nil,
|
||||
'user_id' => user.id,
|
||||
'country' => nil,
|
||||
'raw_data' => {
|
||||
'batt' => 85,
|
||||
'lon' => -74.006,
|
||||
'acc' => 8,
|
||||
'bs' => 2,
|
||||
'inrids' => ['5f1d1b'],
|
||||
'BSSID' => 'b0:f2:8:45:94:33',
|
||||
'SSID' => 'Home Wifi',
|
||||
'vac' => 3,
|
||||
'inregions' => ['home'],
|
||||
'lat' => 40.7128,
|
||||
'topic' => 'owntracks/test/iPhone 12 Pro',
|
||||
't' => 'p',
|
||||
'conn' => 'w',
|
||||
'm' => 1,
|
||||
'tst' => 1_706_965_203,
|
||||
'alt' => 41,
|
||||
'_type' => 'location',
|
||||
'tid' => 'RO',
|
||||
'_http' => true,
|
||||
'ghash' => 'u33d773',
|
||||
'isorcv' => '2024-02-03T13:00:03Z',
|
||||
'isotst' => '2024-02-03T13:00:03Z',
|
||||
'disptst' => '2024-02-03 13:00:03'
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OwnTracks::Params do
|
||||
|
|
@ -15,7 +17,7 @@ RSpec.describe OwnTracks::Params do
|
|||
{
|
||||
latitude: 40.7128,
|
||||
longitude: -74.006,
|
||||
battery_status: 'unknown',
|
||||
battery_status: 'charging',
|
||||
battery: 85,
|
||||
ping: nil,
|
||||
altitude: 41,
|
||||
|
|
@ -25,9 +27,9 @@ RSpec.describe OwnTracks::Params do
|
|||
connection: 'wifi',
|
||||
ssid: 'Home Wifi',
|
||||
bssid: 'b0:f2:8:45:94:33',
|
||||
trigger: 'unknown',
|
||||
trigger: 'background_event',
|
||||
tracker_id: 'RO',
|
||||
timestamp: 1706965203,
|
||||
timestamp: 1_706_965_203,
|
||||
inrids: ['5f1d1b'],
|
||||
in_regions: ['home'],
|
||||
topic: 'owntracks/test/iPhone 12 Pro',
|
||||
|
|
@ -46,7 +48,7 @@ RSpec.describe OwnTracks::Params do
|
|||
't' => 'p',
|
||||
'conn' => 'w',
|
||||
'm' => 1,
|
||||
'tst' => 1706965203,
|
||||
'tst' => 1_706_965_203,
|
||||
'alt' => 41,
|
||||
'_type' => 'location',
|
||||
'tid' => 'RO',
|
||||
|
|
@ -64,7 +66,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when battery status is unplugged' do
|
||||
let(:raw_point_params) { super().merge(bs: 'u') }
|
||||
let(:raw_point_params) { super().merge(bs: 1) }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:battery_status]).to eq('unplugged')
|
||||
|
|
@ -72,7 +74,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when battery status is charging' do
|
||||
let(:raw_point_params) { super().merge(bs: 'c') }
|
||||
let(:raw_point_params) { super().merge(bs: 2) }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:battery_status]).to eq('charging')
|
||||
|
|
@ -80,7 +82,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when battery status is full' do
|
||||
let(:raw_point_params) { super().merge(bs: 'f') }
|
||||
let(:raw_point_params) { super().merge(bs: 3) }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:battery_status]).to eq('full')
|
||||
|
|
@ -96,7 +98,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is circular_region_event' do
|
||||
let(:raw_point_params) { super().merge(m: 'c') }
|
||||
let(:raw_point_params) { super().merge(t: 'c') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('circular_region_event')
|
||||
|
|
@ -104,7 +106,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is beacon_event' do
|
||||
let(:raw_point_params) { super().merge(m: 'b') }
|
||||
let(:raw_point_params) { super().merge(t: 'b') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('beacon_event')
|
||||
|
|
@ -112,7 +114,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is report_location_message_event' do
|
||||
let(:raw_point_params) { super().merge(m: 'r') }
|
||||
let(:raw_point_params) { super().merge(t: 'r') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('report_location_message_event')
|
||||
|
|
@ -120,7 +122,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is manual_event' do
|
||||
let(:raw_point_params) { super().merge(m: 'u') }
|
||||
let(:raw_point_params) { super().merge(t: 'u') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('manual_event')
|
||||
|
|
@ -128,7 +130,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is timer_based_event' do
|
||||
let(:raw_point_params) { super().merge(m: 't') }
|
||||
let(:raw_point_params) { super().merge(t: 't') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('timer_based_event')
|
||||
|
|
@ -136,7 +138,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is settings_monitoring_event' do
|
||||
let(:raw_point_params) { super().merge(m: 'v') }
|
||||
let(:raw_point_params) { super().merge(t: 'v') }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('settings_monitoring_event')
|
||||
|
|
@ -184,7 +186,7 @@ RSpec.describe OwnTracks::Params do
|
|||
end
|
||||
|
||||
context 'when trigger is unknown' do
|
||||
let(:raw_point_params) { super().merge(m: 'unknown') }
|
||||
before { raw_point_params[:t] = 'unknown' }
|
||||
|
||||
it 'returns parsed params' do
|
||||
expect(params[:trigger]).to eq('unknown')
|
||||
|
|
|
|||
Loading…
Reference in a new issue