ruby-macrodroid 0.9.6 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 652f6174d50060ca2b7e3197c2bc79062ed6af498b1982ef8c73e27b0422ad85
4
- data.tar.gz: 86096eb1c1fef612666065e0e3d48c619b4768d801723b6beaa273687d643fec
3
+ metadata.gz: 7c377e6586f261b43617f7daa117872cab4a642476c7923a6b353e2d3adfea8b
4
+ data.tar.gz: 73dc4c91553017f35fa6d37afcda647ff1e14fd732f6bb52c89266fde62c66f0
5
5
  SHA512:
6
- metadata.gz: f9705342b8176dc48a5bfca362a17e340bfd56f67d2eafa3b20602fa493d02cbf5a9cbfe13b2dfb02565a74bb02bf01477de6884151a659fab4500c4b2cbfea4
7
- data.tar.gz: 6e7bae11b8cf64ff3b0efd4f852f6bb8c2e419aa8d25693aeb894dde64c063c2dbcf9abe9bddf5dbe87cb630d8fa6e6c183d105b6b71fedee804918a79467489
6
+ metadata.gz: 1fc6439e1bb63fde2828ba2cc3593223b0fdf9ec22c6caf2e926456973663f85cb0f389d641503e41e82c1b660412781485b8ef8b280b55fe7e077ebdaa64cce
7
+ data.tar.gz: 2056084f2c420f6f7a3328c92f6ebad1caf150a0a34ea353f1ce2fce5c22c237841ce02dbea3a805eb73baad69a4beb57050570a593a63052559a498fb22c416
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -110,16 +110,19 @@ class MacroDroid
110
110
  using Params
111
111
 
112
112
  attr_reader :macros, :geofences, :yaml
113
- attr_accessor :deviceid, :remote_url
113
+ attr_accessor :deviceid, :remote_url, :picture_path
114
114
 
115
115
  # note: The deviceid can only be found from an existing Webhook trigger,
116
116
  # generated from MacroDroid itself.
117
117
 
118
- def initialize(obj=nil, deviceid: nil, remote_url: nil, debug: false)
118
+ def initialize(obj=nil, deviceid: nil, remote_url: nil,
119
+ picture_path: '/storage/emulated/0/Pictures', debug: false)
119
120
 
120
121
  @deviceid, @remote_url, @debug = deviceid, remote_url, debug
122
+ @picture_path = picture_path
121
123
 
122
124
  @geofences = {}
125
+ @macros = []
123
126
 
124
127
  if obj then
125
128
 
@@ -143,34 +146,7 @@ class MacroDroid
143
146
 
144
147
  if s =~ /m(?:acro)?:\s/ then
145
148
 
146
- puts 'before RowX.new' if @debug
147
-
148
- s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
149
- .gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
150
- .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
151
- .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
152
-
153
- a = s2.split(/(?=^macro:)/)
154
-
155
- raw_geofences = a.shift if a.first =~ /^geofence/
156
- raw_macros = a.join
157
- #raw_macros, raw_geofences .reverse
158
-
159
- puts 'raw_macros: ' + raw_macros.inspect if @debug
160
-
161
- if raw_geofences then
162
-
163
- geoxml = RowX.new(raw_geofences).to_xml
164
-
165
- geodoc = Rexle.new(geoxml)
166
- geofences = geodoc.root.xpath('item/geofence')
167
- @geofences = fetch_geofences(geofences) if geofences.any?
168
-
169
- end
170
-
171
- xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
172
- puts 'xml: ' + xml if @debug
173
- import_rowxml(xml)
149
+ import_txt(s)
174
150
 
175
151
  elsif s =~ /^# /
176
152
  xml = pc_to_xml(s)
@@ -227,6 +203,10 @@ class MacroDroid
227
203
  def export(filepath)
228
204
  FileX.write filepath, to_json
229
205
  end
206
+
207
+ def import(s)
208
+ import_txt(s)
209
+ end
230
210
 
231
211
  def to_json()
232
212
 
@@ -334,7 +314,8 @@ class MacroDroid
334
314
  # puts '@geofences: ' + @geofences.inspect if @debug
335
315
 
336
316
  m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
337
- remote_url: @remote_url, debug: @debug )
317
+ remote_url: @remote_url, picture_path: @picture_path,
318
+ parent: self, debug: @debug )
338
319
  m.import_h(macro)
339
320
  m
340
321
 
@@ -353,14 +334,50 @@ class MacroDroid
353
334
  puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
354
335
  geofences = @geofences
355
336
 
356
- @macros = doc.root.xpath('item').map do |node|
337
+ a = doc.root.xpath('item').map do |node|
357
338
  puts ('geofences: ' + geofences.inspect).highlight if @debug
358
339
  Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
359
- remote_url: @remote_url, debug: @debug).import_xml(node)
340
+ remote_url: @remote_url, picture_path: @picture_path,
341
+ parent: self, debug: @debug).import_xml(node)
360
342
 
361
343
  end
344
+
345
+ @macros.concat a
362
346
 
363
- end
347
+ end
348
+
349
+ def import_txt(s)
350
+
351
+ puts 'before RowX.new' if @debug
352
+
353
+ s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
354
+ .gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
355
+ .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
356
+ .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
357
+
358
+ a = s2.split(/(?=^macro:)/)
359
+
360
+ raw_geofences = a.shift if a.first =~ /^geofence/
361
+ raw_macros = a.join
362
+ #raw_macros, raw_geofences .reverse
363
+
364
+ puts 'raw_macros: ' + raw_macros.inspect if @debug
365
+
366
+ if raw_geofences then
367
+
368
+ geoxml = RowX.new(raw_geofences).to_xml
369
+
370
+ geodoc = Rexle.new(geoxml)
371
+ geofences = geodoc.root.xpath('item/geofence')
372
+ @geofences = fetch_geofences(geofences) if geofences.any?
373
+
374
+ end
375
+
376
+ xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
377
+ puts 'xml: ' + xml if @debug
378
+ import_rowxml(xml)
379
+
380
+ end
364
381
 
365
382
  def import_xml(raws)
366
383
 
@@ -380,7 +397,8 @@ class MacroDroid
380
397
  @macros = doc.root.xpath('macro').map do |node|
381
398
  puts 'node: ' + node.inspect if @debug
382
399
  Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
383
- debug: @debug).import_xml(node)
400
+ picture_path: @picture_path, parent: self, debug: @debug)\
401
+ .import_xml(node)
384
402
 
385
403
  end
386
404
  end
@@ -150,7 +150,7 @@ class OpenWebPageAction < ApplicationAction
150
150
 
151
151
  def initialize(obj={}, macro=nil)
152
152
 
153
- $debug = true
153
+ $debug = false
154
154
  puts ('obj: ' + obj.inspect).debug if $debug
155
155
 
156
156
  h = if obj.is_a? Hash then
@@ -190,9 +190,9 @@ class OpenWebPageAction < ApplicationAction
190
190
  #h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
191
191
 
192
192
  options = {
193
- variable_to_save_response: {:string_value=>"", :name=>"coords",
194
- decimal_value: 0.0, isLocal: true, m_boolean_value: false,
195
- excludeFromLog: false, int_value: 0, type: 2},
193
+ #variable_to_save_response: {:string_value=>"", :name=>"coords",
194
+ #decimal_value: 0.0, isLocal: true, m_boolean_value: false,
195
+ #excludeFromLog: false, int_value: 0, type: 2},
196
196
  url_to_open: '',
197
197
  http_get: true,
198
198
  disable_url_encode: false,
@@ -284,11 +284,64 @@ end
284
284
  #
285
285
  class TakePictureAction < CameraAction
286
286
 
287
- def initialize(h={})
287
+ def initialize(obj=nil)
288
+
289
+
290
+ h = if obj.is_a? Hash then
291
+
292
+ macro = obj[:macro]
293
+ obj.delete :macro
294
+ obj
295
+
296
+
297
+ elsif obj.is_a? Array
298
+
299
+ e, macro = obj
300
+
301
+ #puts 'e: ' + e.xml.inspect
302
+
303
+ a = e.xpath('item/*')
304
+
305
+ if a.any? then
306
+
307
+ h2 = a.map {|node| [node.name.to_sym, node.text.to_s.strip]}.to_h
308
+
309
+ desc = ''
310
+
311
+ if h2[:description] then
312
+
313
+ desc = h2[:description]
314
+ h2.delete :description
315
+ #puts 'desc: ' + desc.inspect
316
+
317
+ if desc.length > 1 then
318
+
319
+ flash = case desc
320
+ when /Flash On/i
321
+ 1
322
+ when /Flash Auto/i
323
+ 2
324
+ else
325
+ 0
326
+ end
327
+
288
328
 
329
+ end
330
+
331
+ end
332
+
333
+ {
334
+ use_front_camera: (desc =~ /Front Facing/ ? true : false),
335
+ flash_option: flash
336
+ }.merge(h2)
337
+
338
+
339
+ end
340
+ end
341
+
289
342
  options = {
290
- new_path: '/storage/sdcard1/DCIM/Camera',
291
- path: '/storage/sdcard1/DCIM/Camera',
343
+ new_path: macro.picture_path,
344
+ path: macro.picture_path,
292
345
  show_icon: true,
293
346
  use_front_camera: true,
294
347
  flash_option: 0
@@ -304,7 +357,22 @@ class TakePictureAction < CameraAction
304
357
  end
305
358
 
306
359
  def to_s(colour: false, indent: 0)
307
- 'Take Picture'
360
+
361
+ flash = case @h[:flash_option]
362
+ when 0
363
+ ''
364
+ when 1
365
+ 'Flash On'
366
+ when 2
367
+ 'Flash Auto'
368
+ end
369
+
370
+ @s = 'Take Picture'# + @h.inspect
371
+ a = [@h[:use_front_camera] ? 'Front Facing' : 'Rear Facing']
372
+ a << flash if flash.length > 0
373
+ @s += "\n" + a.join(', ')
374
+ super()
375
+
308
376
  end
309
377
 
310
378
  end
@@ -401,10 +469,14 @@ end
401
469
 
402
470
  # Conditions/Loops
403
471
  #
404
- class IfConditionAction < Action
405
472
 
473
+ class IfAction < Action
474
+ using ColouredText
475
+
406
476
  def initialize(obj=nil)
407
-
477
+
478
+ $debug = false
479
+
408
480
  options = {
409
481
  a: true,
410
482
  constraint_list: []
@@ -424,10 +496,10 @@ class IfConditionAction < Action
424
496
  super()
425
497
  puts 'e.xml: ' + e.xml if $debug
426
498
  puts 'e.text: ' + e.text.to_s.strip if $debug
427
- raw_txt = e.text.to_s.strip[/^if [^$]+/i] || e.text('item/description')
499
+ raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description')
428
500
  puts 'raw_txt: ' + raw_txt.inspect if $debug
429
501
 
430
- clause = raw_txt[/^If (.*)/i,1]
502
+ clause = raw_txt[/^#{@label}(.*)/i,1]
431
503
  puts 'clause: ' + clause.inspect if $debug
432
504
  conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
433
505
  puts 'conditions: ' + conditions.inspect if $debug
@@ -446,6 +518,7 @@ class IfConditionAction < Action
446
518
 
447
519
  # find any nested actions
448
520
  item = e.element('item')
521
+ #puts ('item: ' + item.xml.inspect).debug if $debug
449
522
 
450
523
  if item then
451
524
 
@@ -466,19 +539,13 @@ class IfConditionAction < Action
466
539
 
467
540
  end
468
541
 
469
-
470
-
471
-
472
-
473
- @label = 'If '
474
-
475
542
  end
476
-
543
+
477
544
  def to_s(colour: false, indent: 0)
478
545
 
479
546
  h = @h.clone
480
547
  #h.delete :macro
481
- @s = 'If '
548
+ @s = @label
482
549
  operator = @h[:is_or_condition] ? 'OR' : 'AND'
483
550
  constraints = @constraints.map \
484
551
  {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
@@ -489,7 +556,18 @@ class IfConditionAction < Action
489
556
  out << s + constraints
490
557
  out.join("\n")
491
558
 
492
- end
559
+ end
560
+
561
+ end
562
+
563
+ class IfConditionAction < IfAction
564
+
565
+ def initialize(obj=nil)
566
+
567
+ @label = 'If '
568
+ super(obj)
569
+
570
+ end
493
571
 
494
572
  end
495
573
 
@@ -537,41 +615,15 @@ class ElseAction < Action
537
615
 
538
616
  end
539
617
 
540
- class ElseIfConditionAction < Action
618
+ class ElseIfConditionAction < IfAction
541
619
 
542
- def initialize(h={})
543
-
544
- options = {
545
- constraint_list: ''
546
- }
547
-
548
- super(options.merge h)
549
- @label = 'Else If '
620
+ def initialize(obj=nil)
550
621
 
551
- end
552
-
553
- def to_s(colour: false, indent: 0)
554
-
555
- h = @h.clone
556
- h.delete :macro
557
- @s = 'Else If '
558
- operator = @h[:is_or_condition] ? 'OR' : 'AND'
559
- constraints = @constraints.map \
560
- {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
561
-
562
- out = []
563
- out << "; %s" % @h[:comment] if @h[:comment]
564
- s = @s.lines.map {|x| (' ' * indent) + x}.join
565
- out << s + constraints
566
- out.join("\n")
622
+ @label = 'Else If '
623
+ super(obj)
567
624
 
568
- end
569
-
570
- def to_summary(colour: false)
571
- 'foo'
572
625
  end
573
-
574
-
626
+
575
627
  end
576
628
 
577
629
 
@@ -709,6 +761,9 @@ class SetHotspotAction < ConnectivityAction
709
761
 
710
762
  def initialize(h={})
711
763
 
764
+ # to-do: check when *disable hotspot*, is the
765
+ # *enable wifi* option selected?
766
+
712
767
  options = {
713
768
  device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
714
769
 
@@ -719,8 +774,15 @@ class SetHotspotAction < ConnectivityAction
719
774
  end
720
775
 
721
776
  def to_s(colour: false, indent: 0)
722
- action = @h[:turn_wifi_on] ? 'Enable' : 'Disable'
723
- action + ' HotSpot'
777
+
778
+ @s = "%s HotSpot" % [@h[:state] == 0 ? 'Enable' : 'Disable']
779
+
780
+ if @h[:state] == 1 then
781
+ @s += "\n" + (@h[:turn_wifi_on] ? 'Enable WiFi' : 'Don\'t Enable Wifi')
782
+ end
783
+
784
+ super()
785
+
724
786
  end
725
787
  end
726
788
 
@@ -1644,6 +1706,51 @@ class ConfirmNextAction < Action
1644
1706
 
1645
1707
  end
1646
1708
 
1709
+ class DisableMacroAction < Action
1710
+
1711
+ def initialize(obj=nil)
1712
+
1713
+ h = if obj.is_a? Hash then
1714
+
1715
+ obj
1716
+
1717
+ elsif obj.is_a? Array
1718
+
1719
+ e, macro, h2 = obj
1720
+
1721
+ # find the macro guid for the given name
1722
+ name = e.text('item/description').to_s
1723
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1724
+
1725
+ h3 = if found then
1726
+ {macro_name: found.title, GUID: found.guid}
1727
+ else
1728
+ {macro_name: name}
1729
+ end
1730
+
1731
+ h3.merge h2
1732
+
1733
+ end
1734
+
1735
+ # state: 0 = enable, 1 = disable, 2 = toggle
1736
+
1737
+ options = {macro_name: "Change brightness", state: 1, GUID: nil}
1738
+ super(options.merge h)
1739
+
1740
+ end
1741
+
1742
+ def to_s(colour: false, indent: 0)
1743
+
1744
+ state = %w(Enable Disable Toggle)[@h[:state]]
1745
+ @s = state + ' macro'# + @h.inspect
1746
+ @s += "\n" + @h[:macro_name]
1747
+ super()
1748
+
1749
+ end
1750
+
1751
+ alias to_summary to_s
1752
+ end
1753
+
1647
1754
  # MacroDroid Specific
1648
1755
  #
1649
1756
  class ExportMacrosAction < Action
@@ -1810,7 +1917,7 @@ class PauseAction < Action
1810
1917
  options = {
1811
1918
  delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
1812
1919
  }
1813
- super(h)
1920
+ super(options.merge h)
1814
1921
 
1815
1922
  end
1816
1923