Class: KeepAwakeAction

Inherits:
ScreenAction show all
Defined in:
lib/ruby-macrodroid/actions.rb

Overview

Category: Screen

options:

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

Instance Attribute Summary

Attributes inherited from Action

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Action

#invoke

Methods included from ObjectX

#action_to_object, #object_create, #varify

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ KeepAwakeAction

Returns a new instance of KeepAwakeAction.



2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
# File 'lib/ruby-macrodroid/actions.rb', line 2803

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

Instance Method Details

#to_s(colour: false, indent: 0) ⇒ Object



2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
# File 'lib/ruby-macrodroid/actions.rb', line 2853

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