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.



2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
# File 'lib/ruby-macrodroid/actions.rb', line 2599

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



2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
# File 'lib/ruby-macrodroid/actions.rb', line 2649

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