openhab-scripting 2.16.2 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab.rb +12 -16
  3. data/lib/openhab/core/entity_lookup.rb +173 -0
  4. data/lib/openhab/core/openhab_setup.rb +31 -0
  5. data/lib/openhab/core/osgi.rb +61 -0
  6. data/lib/openhab/dsl/actions.rb +105 -0
  7. data/lib/openhab/dsl/dsl.rb +49 -0
  8. data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
  9. data/lib/openhab/dsl/group.rb +100 -0
  10. data/lib/openhab/dsl/items/datetime_item.rb +97 -0
  11. data/lib/openhab/dsl/items/items.rb +46 -0
  12. data/lib/openhab/dsl/items/number_item.rb +352 -0
  13. data/lib/openhab/dsl/items/rollershutter_item.rb +179 -0
  14. data/lib/openhab/dsl/items/string_item.rb +120 -0
  15. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
  16. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
  17. data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
  18. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
  19. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
  20. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
  21. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
  22. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
  23. data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
  24. data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
  25. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
  26. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
  27. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
  28. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
  29. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
  30. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +8 -0
  31. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
  32. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +32 -0
  33. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
  34. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
  35. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
  36. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
  37. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
  38. data/lib/openhab/dsl/monkey_patch/types/types.rb +9 -0
  39. data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +33 -0
  40. data/lib/openhab/dsl/persistence.rb +25 -0
  41. data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
  42. data/lib/openhab/dsl/rules/guard.rb +134 -0
  43. data/lib/openhab/dsl/rules/property.rb +102 -0
  44. data/lib/openhab/dsl/rules/rule.rb +116 -0
  45. data/lib/openhab/dsl/rules/rule_config.rb +151 -0
  46. data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
  47. data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
  48. data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
  49. data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
  50. data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
  51. data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
  52. data/lib/openhab/dsl/states.rb +61 -0
  53. data/lib/openhab/dsl/things.rb +91 -0
  54. data/lib/openhab/dsl/time_of_day.rb +232 -0
  55. data/lib/openhab/dsl/timers.rb +77 -0
  56. data/lib/openhab/dsl/types/datetime.rb +326 -0
  57. data/lib/openhab/dsl/types/quantity.rb +290 -0
  58. data/lib/openhab/dsl/units.rb +39 -0
  59. data/lib/openhab/log/configuration.rb +21 -0
  60. data/lib/openhab/log/logger.rb +172 -0
  61. data/lib/openhab/version.rb +1 -1
  62. metadata +60 -58
  63. data/lib/openhab/configuration.rb +0 -16
  64. data/lib/openhab/core/cron.rb +0 -27
  65. data/lib/openhab/core/debug.rb +0 -34
  66. data/lib/openhab/core/dsl.rb +0 -51
  67. data/lib/openhab/core/dsl/actions.rb +0 -107
  68. data/lib/openhab/core/dsl/entities.rb +0 -147
  69. data/lib/openhab/core/dsl/group.rb +0 -102
  70. data/lib/openhab/core/dsl/items/items.rb +0 -51
  71. data/lib/openhab/core/dsl/items/number_item.rb +0 -323
  72. data/lib/openhab/core/dsl/items/string_item.rb +0 -122
  73. data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
  74. data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
  75. data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
  76. data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
  77. data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
  78. data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
  79. data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
  80. data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
  81. data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
  82. data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
  83. data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
  84. data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
  85. data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
  86. data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
  87. data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
  88. data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
  89. data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
  90. data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
  91. data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
  92. data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
  93. data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
  94. data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
  95. data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
  96. data/lib/openhab/core/dsl/persistence.rb +0 -27
  97. data/lib/openhab/core/dsl/property.rb +0 -96
  98. data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
  99. data/lib/openhab/core/dsl/rule/guard.rb +0 -136
  100. data/lib/openhab/core/dsl/rule/rule.rb +0 -117
  101. data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
  102. data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
  103. data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
  104. data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
  105. data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
  106. data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
  107. data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
  108. data/lib/openhab/core/dsl/states.rb +0 -63
  109. data/lib/openhab/core/dsl/things.rb +0 -93
  110. data/lib/openhab/core/dsl/time_of_day.rb +0 -231
  111. data/lib/openhab/core/dsl/timers.rb +0 -79
  112. data/lib/openhab/core/dsl/types/quantity.rb +0 -292
  113. data/lib/openhab/core/dsl/units.rb +0 -41
  114. data/lib/openhab/core/log.rb +0 -170
  115. data/lib/openhab/core/patch_load_path.rb +0 -7
  116. data/lib/openhab/core/startup_delay.rb +0 -23
  117. data/lib/openhab/osgi.rb +0 -59
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'core/log'
4
-
5
- module OpenHAB
6
- module Core
7
- module DSL
8
- module Rule
9
- #
10
- # Module holds rule triggers
11
- #
12
- module Triggers
13
- include Logging
14
-
15
- #
16
- # Create a trigger for when an item or group receives a command
17
- #
18
- # The commands/commands parameters are replicated for DSL fluency
19
- #
20
- # @param [Array] items Array of items to create trigger for
21
- # @param [Array] command commands to match for trigger
22
- # @param [Array] commands commands to match for trigger
23
- #
24
- #
25
- def received_command(*items, command: nil, commands: nil)
26
- items.flatten.each do |item|
27
- logger.trace("Creating received command trigger for item(#{item})"\
28
- "command(#{command}) commands(#{commands})")
29
-
30
- # Combine command and commands, doing union so only a single nil will be in the combined array.
31
- combined_commands = combine_commands(command, commands)
32
- create_received_trigger(combined_commands, item)
33
- end
34
- end
35
-
36
- private
37
-
38
- #
39
- # Create a received trigger based on item type
40
- #
41
- # @param [Array] commands to create trigger for
42
- # @param [Object] item to create trigger for
43
- #
44
- #
45
- def create_received_trigger(commands, item)
46
- commands.each do |command|
47
- if item.is_a? GroupItems
48
- config, trigger = create_group_command_trigger(item)
49
- else
50
- config, trigger = create_item_command_trigger(item)
51
- end
52
- config['command'] = command.to_s unless command.nil?
53
- append_trigger(trigger, config)
54
- end
55
- end
56
-
57
- #
58
- # Create trigger for item commands
59
- #
60
- # @param [Item] item to create trigger for
61
- #
62
- # @return [Array<Hash,Trigger>] first element is hash of trigger config properties
63
- # second element is trigger type
64
- #
65
- def create_item_command_trigger(item)
66
- config = { 'itemName' => item.name }
67
- trigger = Trigger::ITEM_COMMAND
68
- [config, trigger]
69
- end
70
-
71
- #
72
- # Create trigger for group items
73
- #
74
- # @param [Group] group to create trigger for
75
- #
76
- # @return [Array<Hash,Trigger>] first element is hash of trigger config properties
77
- # second element is trigger type
78
- #
79
- def create_group_command_trigger(group)
80
- config = { 'groupName' => group.group.name }
81
- trigger = Trigger::GROUP_COMMAND
82
- [config, trigger]
83
- end
84
-
85
- #
86
- # Combine command and commands into a single array
87
- #
88
- # @param [Array] command list of commands to trigger on
89
- # @param [Array] commands list of commands to trigger on
90
- #
91
- # @return [Array] Combined flattened and compacted list of commands
92
- #
93
- def combine_commands(command, commands)
94
- combined_commands = ([command] | [commands]).flatten
95
-
96
- # If either command or commands has a value and one is nil, we need to remove nil from the array.
97
- # If it is only now a single nil value, we leave the nil in place, so that we create a trigger
98
- # That isn't looking for a specific command.
99
- combined_commands = combined_commands.compact unless combined_commands.all?(&:nil?)
100
- combined_commands
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,160 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
- require 'core/dsl/time_of_day'
5
- require 'core/cron'
6
-
7
- module OpenHAB
8
- module Core
9
- module DSL
10
- module Rule
11
- #
12
- # Cron type rules
13
- #
14
- module Triggers
15
- java_import org.openhab.core.automation.util.TriggerBuilder
16
- java_import org.openhab.core.config.core.Configuration
17
-
18
- include OpenHAB::Core::DSL::Rule
19
- extend OpenHAB::Core::Cron
20
-
21
- # @return [Map] Map of days of the week from symbols to to OpenHAB cron strings
22
- DAY_OF_WEEK_MAP = {
23
- monday: 'MON',
24
- tuesday: 'TUE',
25
- wednesday: 'WED',
26
- thursday: 'THU',
27
- friday: 'FRI',
28
- saturday: 'SAT',
29
- sunday: 'SUN'
30
- }.freeze
31
-
32
- private_constant :DAY_OF_WEEK_MAP
33
-
34
- # @return [MAP] Converts the DAY_OF_WEEK_MAP to map used by Cron Expression
35
- DAY_OF_WEEK_EXPRESSION_MAP = DAY_OF_WEEK_MAP.transform_values { |v| cron_expression_map.merge(dow: v) }
36
-
37
- private_constant :DAY_OF_WEEK_EXPRESSION_MAP
38
-
39
- # @return [Map] Create a set of cron expressions based on different time intervals
40
- EXPRESSION_MAP = {
41
- second: cron_expression_map,
42
- minute: cron_expression_map.merge(second: '0'),
43
- hour: cron_expression_map.merge(second: '0', minute: '0'),
44
- day: cron_expression_map.merge(second: '0', minute: '0', hour: '0'),
45
- week: cron_expression_map.merge(second: '0', minute: '0', hour: '0', dow: 'MON'),
46
- month: cron_expression_map.merge(second: '0', minute: '0', hour: '0', dom: '1'),
47
- year: cron_expression_map.merge(second: '0', minute: '0', hour: '0', dom: '1', month: '1')
48
- }.merge(DAY_OF_WEEK_EXPRESSION_MAP)
49
- .freeze
50
-
51
- private_constant :EXPRESSION_MAP
52
-
53
- #
54
- # Create a rule that executes at the specified interval
55
- #
56
- # @param [Object] value Symbol or Duration to execute this rule
57
- # @param [Object] at TimeOfDay or String representing TimeOfDay in which to execute rule
58
- #
59
- #
60
- def every(value, at: nil)
61
- cron_expression = case value
62
- when Symbol then cron_from_symbol(value, at)
63
- when Java::JavaTime::Duration then cron_from_duration(value, at)
64
- else raise ArgumentExpression, 'Unknown interval'
65
- end
66
- cron(cron_expression)
67
- end
68
-
69
- #
70
- # Create a OpenHAB Cron trigger
71
- #
72
- # @param [String] expression OpenHAB style cron expression
73
- #
74
- def cron(expression)
75
- @triggers << Trigger.trigger(type: Trigger::CRON, config: { 'cronExpression' => expression })
76
- end
77
-
78
- private
79
-
80
- #
81
- # Create a cron map from a duration
82
- #
83
- # @param [java::time::Duration] duration
84
- # @param [Object] at TimeOfDay or String representing time of day
85
- #
86
- # @return [Hash] map describing cron expression
87
- #
88
- def cron_from_duration(duration, at)
89
- raise ArgumentError, '"at" cannot be used with duration' if at
90
-
91
- map_to_cron(duration_to_map(duration))
92
- end
93
-
94
- #
95
- # Create a cron map from a symbol
96
- #
97
- # @param [Symbol] symbol
98
- # @param [Object] at TimeOfDay or String representing time of day
99
- #
100
- # @return [Hash] map describing cron expression created from symbol
101
- #
102
- def cron_from_symbol(symbol, at)
103
- expression_map = EXPRESSION_MAP[symbol]
104
- expression_map = at_condition(expression_map, at) if at
105
- map_to_cron(expression_map)
106
- end
107
-
108
- #
109
- # Map cron expression to to cron string
110
- #
111
- # @param [Map] map of cron expression
112
- #
113
- # @return [String] OpenHAB cron string
114
- #
115
- def map_to_cron(map)
116
- %i[second minute hour dom month dow].map { |field| map.fetch(field) }.join(' ')
117
- end
118
-
119
- #
120
- # Convert a Java Duration to a map for the map_to_cron method
121
- #
122
- # @param duration [Java::JavaTime::Duration] The duration object
123
- #
124
- # @return [Hash] a map suitable for map_to_cron
125
- #
126
- def duration_to_map(duration)
127
- if duration.to_millis_part.zero? && duration.to_nanos_part.zero? && duration.to_days.zero?
128
- %i[second minute hour].each do |unit|
129
- to_unit_part = duration.public_send("to_#{unit}s_part")
130
- next unless to_unit_part.positive?
131
-
132
- to_unit = duration.public_send("to_#{unit}s")
133
- break unless to_unit_part == to_unit
134
-
135
- return EXPRESSION_MAP[unit].merge(unit => "*/#{to_unit}")
136
- end
137
- end
138
- raise ArgumentError, "Cron Expression not supported for duration: #{duration}"
139
- end
140
-
141
- #
142
- # If an at time is provided, parse that and merge the new fields into the expression.
143
- #
144
- # @param [<Type>] expression_map <description>
145
- # @param [<Type>] at_time <description>
146
- #
147
- # @return [<Type>] <description>
148
- #
149
- def at_condition(expression_map, at_time)
150
- if at_time
151
- tod = at_time.is_a?(TimeOfDay) ? at_time : TimeOfDay.parse(at_time)
152
- expression_map = expression_map.merge(hour: tod.hour, minute: tod.minute, second: tod.second)
153
- end
154
- expression_map
155
- end
156
- end
157
- end
158
- end
159
- end
160
- end
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'securerandom'
4
- require 'java'
5
-
6
- module OpenHAB
7
- module Core
8
- module DSL
9
- module Rule
10
- #
11
- # Module holds rule triggers
12
- #
13
- module Triggers
14
- #
15
- # Create a trigger for a thing
16
- #
17
- # @param [Thing] thing to create trigger for
18
- # @param [Trigger] trigger to map with thing
19
- # @param [State] to for thing
20
- # @param [State] from state of thing
21
- #
22
- # @return [Array] Trigger and config for thing
23
- #
24
- def trigger_for_thing(thing, trigger, to = nil, from = nil)
25
- config = { 'thingUID' => thing.uid.to_s }
26
- config['status'] = trigger_state_from_symbol(to).to_s if to
27
- config['previousStatus'] = trigger_state_from_symbol(from).to_s if from
28
- [trigger, config]
29
- end
30
-
31
- #
32
- # converts object to upcase string if its a symbol
33
- #
34
- # @param [sym] sym potential symbol to convert
35
- #
36
- # @return [String] Upcased symbol as string
37
- #
38
- def trigger_state_from_symbol(sym)
39
- sym.to_s.upcase if (sym.is_a? Symbol) || sym
40
- end
41
-
42
- #
43
- # Append a trigger to the list of triggeres
44
- #
45
- # @param [String] type of trigger to create
46
- # @param [Map] config map describing trigger configuration
47
- #
48
- # @return [Trigger] OpenHAB trigger
49
- #
50
- def append_trigger(type, config)
51
- logger.trace("Creating trigger of type #{type} for #{config}")
52
- trigger = Trigger.trigger(type: type, config: config)
53
- @triggers << trigger
54
- trigger
55
- end
56
-
57
- #
58
- # Class for creating and managing triggers
59
- #
60
- class Trigger
61
- java_import org.openhab.core.automation.util.TriggerBuilder
62
- java_import org.openhab.core.config.core.Configuration
63
-
64
- # @return [String] A channel event trigger
65
- CHANNEL_EVENT = 'core.ChannelEventTrigger'
66
-
67
- # @return [String] A thing status Change trigger
68
- THING_CHANGE = 'core.ThingStatusChangeTrigger'
69
-
70
- # @return [String] A thing status update trigger
71
- THING_UPDATE = 'core.ThingStatusUpdateTrigger'
72
-
73
- # @return [String] An item command trigger
74
- ITEM_COMMAND = 'core.ItemCommandTrigger'
75
-
76
- # @return [String] An item state update trigger
77
- ITEM_STATE_UPDATE = 'core.ItemStateUpdateTrigger'
78
-
79
- # @return [String] An item state change trigger
80
- ITEM_STATE_CHANGE = 'core.ItemStateChangeTrigger'
81
-
82
- # @return [String] A group state change trigger for items in the group
83
- GROUP_STATE_CHANGE = 'core.GroupStateChangeTrigger'
84
-
85
- # @return [String] A group state update trigger for items in the group
86
- GROUP_STATE_UPDATE = 'core.GroupStateUpdateTrigger'
87
-
88
- # @return [String] A group command trigger for items in the group
89
- GROUP_COMMAND = 'core.GroupCommandTrigger'
90
-
91
- # @return [String] A time of day trigger
92
- TIME_OF_DAY = 'timer.TimeOfDayTrigger'
93
-
94
- # @return [String] A cron trigger
95
- CRON = 'timer.GenericCronTrigger'
96
-
97
- #
98
- # Create a trigger
99
- #
100
- # @param [String] type of trigger
101
- # @param [Map] config map
102
- #
103
- # @return [OpenHAB Trigger] configured by type and supplied config
104
- #
105
- def self.trigger(type:, config:)
106
- TriggerBuilder.create
107
- .with_id(uuid)
108
- .with_type_uid(type)
109
- .with_configuration(Configuration.new(config))
110
- .build
111
- end
112
-
113
- #
114
- # Generate a UUID for triggers
115
- #
116
- # @return [String] UUID
117
- #
118
- def self.uuid
119
- SecureRandom.uuid
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
126
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'core/log'
4
-
5
- module OpenHAB
6
- module Core
7
- module DSL
8
- module Rule
9
- #
10
- # Module holds rule triggers
11
- #
12
- module Triggers
13
- include Logging
14
-
15
- #
16
- # Create a trigger when item, group or thing is updated
17
- #
18
- # @param [Array] items array to trigger on updated
19
- # @param [State] to to match for tigger
20
- #
21
- # @return [Trigger] Trigger for updated entity
22
- #
23
- def updated(*items, to: nil)
24
- items.flatten.each do |item|
25
- logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
26
- [to].flatten.each do |to_state|
27
- trigger, config = create_update_trigger(item, to_state)
28
- append_trigger(trigger, config)
29
- end
30
- end
31
- end
32
-
33
- private
34
-
35
- #
36
- # Create a trigger for updates
37
- #
38
- # @param [Object] item Type of item [Group,Thing,Item] to create update trigger for
39
- # @param [State] to_state state restriction on trigger
40
- #
41
- # @return [Array<Hash,String>] first element is a String specifying trigger type
42
- # second element is a Hash configuring trigger
43
- #
44
- def create_update_trigger(item, to_state)
45
- case item
46
- when GroupItems then group_update(item, to_state)
47
- when Thing then thing_update(item, to_state)
48
- else item_update(item, to_state)
49
- end
50
- end
51
-
52
- #
53
- # Create an update trigger for an item
54
- #
55
- # @param [Item] item to create trigger for
56
- # @param [State] to_state optional state restriction for target
57
- #
58
- # @return [Array<Hash,String>] first element is a String specifying trigger type
59
- # second element is a Hash configuring trigger
60
- #
61
- def item_update(item, to_state)
62
- config = { 'itemName' => item.name }
63
- config['state'] = to_state.to_s unless to_state.nil?
64
- trigger = Trigger::ITEM_STATE_UPDATE
65
- [trigger, config]
66
- end
67
-
68
- #
69
- # Create an update trigger for a group
70
- #
71
- # @param [Item] item to create trigger for
72
- # @param [State] to_state optional state restriction for target
73
- #
74
- # @return [Array<Hash,String>] first element is a String specifying trigger type
75
- # second element is a Hash configuring trigger
76
- #
77
- def group_update(item, to_state)
78
- config = { 'groupName' => item.group.name }
79
- config['state'] = to_state.to_s unless to_state.nil?
80
- trigger = Trigger::GROUP_STATE_UPDATE
81
- [trigger, config]
82
- end
83
-
84
- #
85
- # Create an update trigger for a thing
86
- #
87
- # @param [Thing] thing to create trigger for
88
- # @param [State] to_state optional state restriction for target
89
- #
90
- # @return [Array<Hash,String>] first element is a String specifying trigger type
91
- # second element is a Hash configuring trigger
92
- #
93
- def thing_update(thing, to_state)
94
- trigger_for_thing(thing, Trigger::THING_UPDATE, to_state)
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end