class KeepAwakeAction

Category: Screen

options:

keep awake, screen on => enabled: true
disable keep awake    => enabled: false

Public Class Methods

new(obj=nil) click to toggle source
Calls superclass method ScreenAction::new
# File lib/ruby-macrodroid/actions.rb, line 2913
def initialize(obj=nil)
  
  
  h = if obj.is_a? Hash then
  
    obj
    
  elsif obj.is_a? Array
    
    puts 'obj: ' + obj.inspect if $debug
    e, macro = obj
    
    a = e.xpath('item/*')

    txt = e.text('item/description')      
    
    h2 = if txt then
    
      raw_duration = (txt || e.text).to_s
      puts 'raw_duration: ' + raw_duration.inspect  if $debug
      duration = raw_duration[/Screen On - ([^$]+)/i]
      {duration: duration}
      
    elsif a.any? then
      a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
    end      
    
    h2.merge(macro: macro)

  end
  
  puts ('h: ' + h.inspect).debug if $debug
  
  if h[:duration] then
          
    h[:seconds_to_stay_awake_for] =  Subunit.hms_to_seconds(h[:duration])
    
  end

  options = {
    enabled: true,
    permanent: true,
    screen_option: 0,
    seconds_to_stay_awake_for: 0
  }

  super(options.merge h)

end

Public Instance Methods

to_s(colour: false, indent: 0) click to toggle source
# File lib/ruby-macrodroid/actions.rb, line 2963
def to_s(colour: false, indent: 0)
  
  screen = @h[:screen_option] == 0 ? 'Screen On' : 'Screen Off'
  
  if @h[:enabled] then
  
    whenx = if @h[:seconds_to_stay_awake_for] == 0 then
  
    'Until Disabled'
    
    else
      scnds = @h[:seconds_to_stay_awake_for]
      Subunit.new(units={minutes:60, hours:60}, seconds: scnds).strfunit("%x")
    end
    
    "Keep Device Awake\n  " + screen + ' - ' + whenx
    
  else
    'Disable Keep Awake'
  end
  
  
end