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.
2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 |
# File 'lib/ruby-macrodroid/actions.rb', line 2570 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
2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 |
# File 'lib/ruby-macrodroid/actions.rb', line 2620 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 |