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.



2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
# File 'lib/ruby-macrodroid/actions.rb', line 2751

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



2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
# File 'lib/ruby-macrodroid/actions.rb', line 2801

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