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.
2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 |
# File 'lib/ruby-macrodroid/actions.rb', line 2874 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
2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 |
# File 'lib/ruby-macrodroid/actions.rb', line 2924 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 |