Class: KeepAwakeAction
- Inherits:
-
ScreenAction
- Object
- MacroObject
- Action
- ScreenAction
- KeepAwakeAction
- 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
Attributes inherited from MacroObject
Instance Method Summary collapse
-
#initialize(obj = nil) ⇒ KeepAwakeAction
constructor
A new instance of KeepAwakeAction.
- #to_s(colour: false, indent: 0) ⇒ Object
Methods inherited from Action
Methods included from ObjectX
#action_to_object, #object_create, #varify
Methods inherited from MacroObject
Constructor Details
#initialize(obj = nil) ⇒ KeepAwakeAction
Returns a new instance of KeepAwakeAction.
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 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 |
# File 'lib/ruby-macrodroid/actions.rb', line 2610 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 = { enabled: true, permanent: true, screen_option: 0, seconds_to_stay_awake_for: 0 } super(.merge h) end |
Instance Method Details
#to_s(colour: false, indent: 0) ⇒ Object
2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 |
# File 'lib/ruby-macrodroid/actions.rb', line 2660 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 |