mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
Added device struct Liquid attributes
Necessary to generate attributes for Liquid templates. Will soon be used during extension import of TRMNL Recipes in order to supply device information. Milestone: minor
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "core"
|
||||
require "refinements/hash"
|
||||
|
||||
module Terminus
|
||||
module Structs
|
||||
# The device struct.
|
||||
class Device < DB::Struct
|
||||
using Refinements::Hash
|
||||
|
||||
def asleep? at = Time.now, type: Sequel::SQLTime
|
||||
return false unless sleep_start_at && sleep_stop_at
|
||||
|
||||
@@ -33,6 +36,8 @@ module Terminus
|
||||
}
|
||||
end
|
||||
|
||||
def liquid_attributes = {id:, battery_percentage:, wifi_percentage:}.stringify_keys!
|
||||
|
||||
def slug
|
||||
return Core::EMPTY_STRING unless mac_address
|
||||
|
||||
|
||||
@@ -147,6 +147,16 @@ RSpec.describe Terminus::Structs::Device, :db do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#liquid_attributes" do
|
||||
it "answers translation" do
|
||||
expect(device.liquid_attributes).to eq(
|
||||
"id" => device.id,
|
||||
"battery_percentage" => 70,
|
||||
"wifi_percentage" => 90
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#slug" do
|
||||
it "answers string with no colons" do
|
||||
expect(device.slug).to eq("AABBCC112233")
|
||||
|
||||
Reference in New Issue
Block a user