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.
2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 |
# File 'lib/ruby-macrodroid/actions.rb', line 2502 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
2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 |
# File 'lib/ruby-macrodroid/actions.rb', line 2552 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 |