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.



2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
# File 'lib/ruby-macrodroid/actions.rb', line 2671

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



2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
# File 'lib/ruby-macrodroid/actions.rb', line 2721

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