ruby-macrodroid 0.9.9 → 0.9.14

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: 11509c0f7448ef65211af5a07e3191f4292eecfe6c8aa19d79a520b4aaf04f21
4
- data.tar.gz: '08960e2e07bf7c467233be373ae1ae8978302122cba7ab6dfca3c5e28cfe7c46'
3
+ metadata.gz: d2421b1c983ef4223a4e461f70a37be3fa3d2200141ada22a535813b8b9ea94d
4
+ data.tar.gz: cf6a20994ba0a24ca544a1b8bfb75ffab22b6022be1a1f71e4e73b3a344b39e7
5
5
  SHA512:
6
- metadata.gz: 0dd2c7ef1a69f05eb9eb235aac3a8805522f68731c2f980fd730eb0b34ee15066d23ead4f74c3dbd762fc3bfb31d852bdfb5f637d362a4a4cbe0b4e5de17c338
7
- data.tar.gz: 2483d3e4901eb5a839ab3c716674f0fbf0fe925bb94bfa99a71ec5803aab0472235be98dd5773bbb5fd57ee7c8c1c77d242d5e7fbcf5f5bb4dfd09580a24f96a
6
+ metadata.gz: b88c007520adab8bf80f1c0723d803ac2561092c450aee86f2d0e8e26a322646f15dc5df5d9419d1524f8339f0e85a332b603c65124bdb1eebf66b741ca7b1aa
7
+ data.tar.gz: 9ab6f2170600df9813114f9513b1e490496db70a82d432c2e3a3bad2768a67dfe27d7bb0ce84a38c80e28bf4e3a26ed4f8e92f788b1a2bc4c23884fc816a3571
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -122,6 +122,7 @@ class MacroDroid
122
122
  @picture_path = picture_path
123
123
 
124
124
  @geofences = {}
125
+ @macros = []
125
126
 
126
127
  if obj then
127
128
 
@@ -145,34 +146,7 @@ class MacroDroid
145
146
 
146
147
  if s =~ /m(?:acro)?:\s/ then
147
148
 
148
- puts 'before RowX.new' if @debug
149
-
150
- s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
151
- .gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
152
- .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
153
- .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
154
-
155
- a = s2.split(/(?=^macro:)/)
156
-
157
- raw_geofences = a.shift if a.first =~ /^geofence/
158
- raw_macros = a.join
159
- #raw_macros, raw_geofences .reverse
160
-
161
- puts 'raw_macros: ' + raw_macros.inspect if @debug
162
-
163
- if raw_geofences then
164
-
165
- geoxml = RowX.new(raw_geofences).to_xml
166
-
167
- geodoc = Rexle.new(geoxml)
168
- geofences = geodoc.root.xpath('item/geofence')
169
- @geofences = fetch_geofences(geofences) if geofences.any?
170
-
171
- end
172
-
173
- xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
174
- puts 'xml: ' + xml if @debug
175
- import_rowxml(xml)
149
+ import_txt(s)
176
150
 
177
151
  elsif s =~ /^# /
178
152
  xml = pc_to_xml(s)
@@ -229,6 +203,10 @@ class MacroDroid
229
203
  def export(filepath)
230
204
  FileX.write filepath, to_json
231
205
  end
206
+
207
+ def import(s)
208
+ import_txt(s)
209
+ end
232
210
 
233
211
  def to_json()
234
212
 
@@ -337,7 +315,7 @@ class MacroDroid
337
315
 
338
316
  m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
339
317
  remote_url: @remote_url, picture_path: @picture_path,
340
- debug: @debug )
318
+ parent: self, debug: @debug )
341
319
  m.import_h(macro)
342
320
  m
343
321
 
@@ -356,15 +334,50 @@ class MacroDroid
356
334
  puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
357
335
  geofences = @geofences
358
336
 
359
- @macros = doc.root.xpath('item').map do |node|
337
+ a = doc.root.xpath('item').map do |node|
360
338
  puts ('geofences: ' + geofences.inspect).highlight if @debug
361
339
  Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
362
340
  remote_url: @remote_url, picture_path: @picture_path,
363
- debug: @debug).import_xml(node)
341
+ parent: self, debug: @debug).import_xml(node)
364
342
 
365
343
  end
344
+
345
+ @macros.concat a
366
346
 
367
- 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
368
381
 
369
382
  def import_xml(raws)
370
383
 
@@ -384,7 +397,8 @@ class MacroDroid
384
397
  @macros = doc.root.xpath('macro').map do |node|
385
398
  puts 'node: ' + node.inspect if @debug
386
399
  Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
387
- picture_path: @picture_path, debug: @debug).import_xml(node)
400
+ picture_path: @picture_path, parent: self, debug: @debug)\
401
+ .import_xml(node)
388
402
 
389
403
  end
390
404
  end
@@ -589,4 +603,7 @@ require 'ruby-macrodroid/base'
589
603
  require 'ruby-macrodroid/triggers'
590
604
  require 'ruby-macrodroid/actions'
591
605
  require 'ruby-macrodroid/constraints'
606
+ require 'ruby-macrodroid/triggersnlp'
607
+ require 'ruby-macrodroid/actionsnlp'
608
+ require 'ruby-macrodroid/constraintsnlp'
592
609
  require 'ruby-macrodroid/macro'
@@ -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,
@@ -298,7 +298,7 @@ class TakePictureAction < CameraAction
298
298
 
299
299
  e, macro = obj
300
300
 
301
- puts 'e: ' + e.xml.inspect
301
+ #puts 'e: ' + e.xml.inspect
302
302
 
303
303
  a = e.xpath('item/*')
304
304
 
@@ -312,7 +312,7 @@ class TakePictureAction < CameraAction
312
312
 
313
313
  desc = h2[:description]
314
314
  h2.delete :description
315
- puts 'desc: ' + desc.inspect
315
+ #puts 'desc: ' + desc.inspect
316
316
 
317
317
  if desc.length > 1 then
318
318
 
@@ -469,10 +469,14 @@ end
469
469
 
470
470
  # Conditions/Loops
471
471
  #
472
- class IfConditionAction < Action
473
472
 
473
+ class IfAction < Action
474
+ using ColouredText
475
+
474
476
  def initialize(obj=nil)
475
-
477
+
478
+ $debug = false
479
+
476
480
  options = {
477
481
  a: true,
478
482
  constraint_list: []
@@ -492,10 +496,10 @@ class IfConditionAction < Action
492
496
  super()
493
497
  puts 'e.xml: ' + e.xml if $debug
494
498
  puts 'e.text: ' + e.text.to_s.strip if $debug
495
- 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')
496
500
  puts 'raw_txt: ' + raw_txt.inspect if $debug
497
501
 
498
- clause = raw_txt[/^If (.*)/i,1]
502
+ clause = raw_txt[/^#{@label}(.*)/i,1]
499
503
  puts 'clause: ' + clause.inspect if $debug
500
504
  conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
501
505
  puts 'conditions: ' + conditions.inspect if $debug
@@ -514,6 +518,7 @@ class IfConditionAction < Action
514
518
 
515
519
  # find any nested actions
516
520
  item = e.element('item')
521
+ #puts ('item: ' + item.xml.inspect).debug if $debug
517
522
 
518
523
  if item then
519
524
 
@@ -534,19 +539,13 @@ class IfConditionAction < Action
534
539
 
535
540
  end
536
541
 
537
-
538
-
539
-
540
-
541
- @label = 'If '
542
-
543
542
  end
544
-
543
+
545
544
  def to_s(colour: false, indent: 0)
546
545
 
547
546
  h = @h.clone
548
547
  #h.delete :macro
549
- @s = 'If '
548
+ @s = @label
550
549
  operator = @h[:is_or_condition] ? 'OR' : 'AND'
551
550
  constraints = @constraints.map \
552
551
  {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
@@ -557,7 +556,18 @@ class IfConditionAction < Action
557
556
  out << s + constraints
558
557
  out.join("\n")
559
558
 
560
- 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
561
571
 
562
572
  end
563
573
 
@@ -605,41 +615,15 @@ class ElseAction < Action
605
615
 
606
616
  end
607
617
 
608
- class ElseIfConditionAction < Action
618
+ class ElseIfConditionAction < IfAction
609
619
 
610
- def initialize(h={})
611
-
612
- options = {
613
- constraint_list: ''
614
- }
615
-
616
- super(options.merge h)
617
- @label = 'Else If '
620
+ def initialize(obj=nil)
618
621
 
619
- end
620
-
621
- def to_s(colour: false, indent: 0)
622
+ @label = 'Else If '
623
+ super(obj)
622
624
 
623
- h = @h.clone
624
- h.delete :macro
625
- @s = 'Else If '
626
- operator = @h[:is_or_condition] ? 'OR' : 'AND'
627
- constraints = @constraints.map \
628
- {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
629
-
630
- out = []
631
- out << "; %s" % @h[:comment] if @h[:comment]
632
- s = @s.lines.map {|x| (' ' * indent) + x}.join
633
- out << s + constraints
634
- out.join("\n")
635
-
636
- end
637
-
638
- def to_summary(colour: false)
639
- 'foo'
640
625
  end
641
-
642
-
626
+
643
627
  end
644
628
 
645
629
 
@@ -904,8 +888,17 @@ end
904
888
  #
905
889
  class SayTimeAction < DateTimeAction
906
890
 
907
- def initialize(h={})
908
-
891
+ def initialize(obj=nil)
892
+
893
+ h = if obj.is_a? Hash then
894
+ obj
895
+ elsif obj.is_a? Array
896
+
897
+ e, macro = obj
898
+ {:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
899
+
900
+ end
901
+
909
902
  options = {
910
903
  :'12_hour' => true
911
904
  }
@@ -926,7 +919,9 @@ class SayTimeAction < DateTimeAction
926
919
  end
927
920
 
928
921
  def to_s(colour: false, indent: 0)
929
- 'Say Current Time'
922
+ @s = 'Say Current Time'
923
+ @s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
924
+ super()
930
925
  end
931
926
 
932
927
  end
@@ -1672,9 +1667,18 @@ class ClearLogAction < LoggingAction
1672
1667
  end
1673
1668
 
1674
1669
 
1670
+ class MacroDroidAction < Action
1671
+
1672
+ def initialize(h={})
1673
+ super(h)
1674
+ @group = 'macrodroid'
1675
+ end
1676
+
1677
+ end
1678
+
1675
1679
  # MacroDroid Specific
1676
1680
  #
1677
- class CancelActiveMacroAction < Action
1681
+ class CancelActiveMacroAction < MacroDroidAction
1678
1682
 
1679
1683
  def initialize(h={})
1680
1684
 
@@ -1698,7 +1702,7 @@ end
1698
1702
 
1699
1703
  # MacroDroid Specific
1700
1704
  #
1701
- class ConfirmNextAction < Action
1705
+ class ConfirmNextAction < MacroDroidAction
1702
1706
 
1703
1707
  def initialize(h={})
1704
1708
 
@@ -1722,9 +1726,54 @@ class ConfirmNextAction < Action
1722
1726
 
1723
1727
  end
1724
1728
 
1729
+ class DisableMacroAction < MacroDroidAction
1730
+
1731
+ def initialize(obj=nil)
1732
+
1733
+ h = if obj.is_a? Hash then
1734
+
1735
+ obj
1736
+
1737
+ elsif obj.is_a? Array
1738
+
1739
+ e, macro, h2 = obj
1740
+
1741
+ # find the macro guid for the given name
1742
+ name = e.text('item/description').to_s
1743
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1744
+
1745
+ h3 = if found then
1746
+ {macro_name: found.title, GUID: found.guid}
1747
+ else
1748
+ {macro_name: name}
1749
+ end
1750
+
1751
+ h3.merge h2
1752
+
1753
+ end
1754
+
1755
+ # state: 0 = enable, 1 = disable, 2 = toggle
1756
+
1757
+ options = {macro_name: "Change brightness", state: 1, GUID: nil}
1758
+ super(options.merge h)
1759
+
1760
+ end
1761
+
1762
+ def to_s(colour: false, indent: 0)
1763
+
1764
+ state = %w(Enable Disable Toggle)[@h[:state]]
1765
+ @s = state + ' macro'# + @h.inspect
1766
+ @s += "\n" + @h[:macro_name]
1767
+ super()
1768
+
1769
+ end
1770
+
1771
+ alias to_summary to_s
1772
+ end
1773
+
1725
1774
  # MacroDroid Specific
1726
1775
  #
1727
- class ExportMacrosAction < Action
1776
+ class ExportMacrosAction < MacroDroidAction
1728
1777
 
1729
1778
  def initialize(h={})
1730
1779
 
@@ -1746,9 +1795,61 @@ class ExportMacrosAction < Action
1746
1795
  end
1747
1796
 
1748
1797
 
1798
+
1799
+ class ForceMacroRunAction < MacroDroidAction
1800
+
1801
+ def initialize(obj=nil)
1802
+
1803
+ h = if obj.is_a? Hash then
1804
+
1805
+ obj
1806
+
1807
+ elsif obj.is_a? Array
1808
+
1809
+ e, macro, h2 = obj
1810
+
1811
+ # find the macro guid for the given name
1812
+ name = e.text('item/description').to_s
1813
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1814
+
1815
+ h3 = if found then
1816
+ {macro_name: found.title, GUID: found.guid}
1817
+ else
1818
+ {macro_name: name}
1819
+ end
1820
+
1821
+ h3.merge h2
1822
+
1823
+ end
1824
+
1825
+ options = {
1826
+ guid: nil, ignore_constraints: true,
1827
+ macro_name: "", use_off_status: false,
1828
+ user_prompt_title: "Run Macro"
1829
+ }
1830
+ super(options.merge h)
1831
+
1832
+ end
1833
+
1834
+ def invoke()
1835
+ super(macro_name: @h[:macro_name])
1836
+ end
1837
+
1838
+ def to_s(colour: false, indent: 0)
1839
+
1840
+ @s = 'Macro Run'# + @h.inspect
1841
+ @s += "\n" + @h[:macro_name]
1842
+ super()
1843
+
1844
+ end
1845
+
1846
+ alias to_summary to_s
1847
+
1848
+ end
1849
+
1749
1850
  # MacroDroid Specific
1750
1851
  #
1751
- class SetVariableAction < Action
1852
+ class SetVariableAction < MacroDroidAction
1752
1853
  using ColouredText
1753
1854
 
1754
1855
  def initialize(obj=nil)
@@ -1838,7 +1939,7 @@ end
1838
1939
 
1839
1940
  # MacroDroid Specific
1840
1941
  #
1841
- class TextManipulationAction < Action
1942
+ class TextManipulationAction < MacroDroidAction
1842
1943
 
1843
1944
  def initialize(h={})
1844
1945
 
@@ -1881,7 +1982,7 @@ end
1881
1982
 
1882
1983
 
1883
1984
 
1884
- class PauseAction < Action
1985
+ class PauseAction < MacroDroidAction
1885
1986
 
1886
1987
  def initialize(h={})
1887
1988