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
2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 |
# File 'lib/ruby-macrodroid/actions.rb', line 2913 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
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 |
# File 'lib/ruby-macrodroid/actions.rb', line 2963 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 |