Files
terminus/app/structs/device.rb
T
Brooke Kuhlmann 60ac391dcb Updated device struct screen attributes to include ID and kind
Ensures uniqueness by passing down the screen kind and associated device ID.

Issue: 326
Milestone: minor
2026-06-10 11:29:13 -06:00

54 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require "core"
module Terminus
module Structs
# The device struct.
class Device < DB::Struct
def asleep? at = Time.now, type: Sequel::SQLTime
return false unless sleep_start_at && sleep_stop_at
now = type.create at.hour, at.min, at.sec
if sleep_stop_at < sleep_start_at
now >= sleep_start_at || now <= sleep_stop_at
else
(sleep_start_at..sleep_stop_at).cover? now
end
end
def display_attributes
{
image_url_timeout: image_timeout,
maximum_compatibility: display_compatibility,
refresh_rate:,
temperature_profile: display_profile,
touchbar_mode: touch_bar,
update_firmware: firmware_update
}
end
def slug
return Core::EMPTY_STRING unless mac_address
mac_address.tr ":", Core::EMPTY_STRING
end
def screen_label(prefix) = "#{prefix} #{id}"
def screen_name(kind) = "#{kind}_#{id}"
def screen_attributes kind
{
device_id: id,
model_id:,
label: screen_label(kind.capitalize),
name: screen_name(kind),
kind:
}
end
end
end
end