Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator Api | Add VehicleTelemetry model #377

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/ioki/model/operator/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class Vehicle < Base
omit_if_nil_on: [:create, :update],
type: :integer

attribute :vehicle_telemetry,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this called telemetry? This is what I currently get back:

                "telemetry": {
                    "battery_level": null,
                    "charging_state": null,
                    "estimated_time_until_full_recharge": null,
                    "id": null,
                    "last_synced_at": null,
                    "remaining_distance": null,
                    "type": "fleet_state/vehicle_telemetry"
                },
                "type": "fleet_state/vehicle"

I guess it's fine at the moment to use the Vehicle model. If the fleet state vehicle digresses further, it might be good to create a new model. But let's see how this evolves 🙂

on: :read,
type: :object,
class_name: 'VehicleTelemetry'

attribute :version,
on: [:update, :read],
omit_if_nil_on: [:update],
Expand Down
33 changes: 33 additions & 0 deletions lib/ioki/model/operator/vehicle_telemetry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Ioki
module Model
module Operator
class VehicleTelemetry < Base
attribute :id,
on: :read,
type: :string

attribute :battery_level,
on: :read,
type: :float

attribute :remaining_distance,
on: :read,
type: :float

attribute :charging_state,
on: :read,
type: :string

attribute :estimated_time_until_full_recharge,
on: :read,
type: :float

attribute :last_synced_at,
on: :read,
type: :date_time
end
end
end
end
1 change: 1 addition & 0 deletions spec/ioki/model/operator/vehicle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
it { is_expected.to define_attribute(:storage_spaces).as(:integer) }
it { is_expected.to define_attribute(:walker_bays).as(:integer) }
it { is_expected.to define_attribute(:wheelchair_bays).as(:integer) }
it { is_expected.to define_attribute(:vehicle_telemetry).as(:object).with(class_name: 'VehicleTelemetry') }
end
10 changes: 10 additions & 0 deletions spec/ioki/model/operator/vehicle_telemetry_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

RSpec.describe Ioki::Model::Operator::VehicleTelemetry do
it { is_expected.to define_attribute(:id).as(:string) }
it { is_expected.to define_attribute(:battery_level).as(:float) }
it { is_expected.to define_attribute(:remaining_distance).as(:float) }
it { is_expected.to define_attribute(:charging_state).as(:string) }
it { is_expected.to define_attribute(:estimated_time_until_full_recharge).as(:float) }
it { is_expected.to define_attribute(:last_synced_at).as(:date_time) }
end