openhab-scripting 4.8.2 → 4.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04e0efcb683ac15c3b82af5e7837412e84b1038a822468de155b5825068e9593
4
- data.tar.gz: 8b2da1406b372c7164a47d3fec3ac5da4d35af8ee3ceb207148f977ad1cab91d
3
+ metadata.gz: 18381f7d16d590838748802e7535c611279c6b251fc5f782f9f11247f856074b
4
+ data.tar.gz: 1f339a40040d41445020eb2a460269eba1088554034a064c1a335e2e85f17be4
5
5
  SHA512:
6
- metadata.gz: 2227a683fa379ca71f96cb1fd5ca0944906a7f94f3413d7d775a0082a99a62f53631215272db38c3ce85984e4ffcbe382d882ab3a3c76a7c06adac69354854e5
7
- data.tar.gz: 91b9855912c8b309b01369f833a1c89845708c61beaf655d08965ab09dd5e0231eec4a6d508f9941934e9b4c8cda36c8ea88db74e7dbbfb9880f8cf233afc65d
6
+ metadata.gz: 3611a93e20e13b0c5a63354e8c1082466f279e7a9b83b5c352a2b357e09f45411035c6bb1baa79575f1c7e9480ae66a9f651a635dba3130b791dcdf9eb3c4f32
7
+ data.tar.gz: 69f57f2931d50f868742682fa8d400348dc93670dd8ba6f6172477bbc02d9e297203d6466030c52d6055cae740b1fa8f05e8889faf7bef655d650105587ccfc5
@@ -11,7 +11,6 @@ module OpenHAB
11
11
  class OSGI
12
12
  include OpenHAB::Log
13
13
 
14
- java_import org.openhab.core.model.script.actions.ScriptExecution
15
14
  java_import org.osgi.framework.FrameworkUtil
16
15
 
17
16
  #
@@ -83,6 +83,7 @@ module OpenHAB
83
83
  def state?
84
84
  !raw_state.is_a?(Types::UnDefType)
85
85
  end
86
+ alias truthy? state?
86
87
 
87
88
  #
88
89
  # Get the item state
@@ -13,13 +13,13 @@ module OpenHAB
13
13
  include OpenHAB::DSL::Rules::Property
14
14
 
15
15
  prop_array(:only_if) do |item|
16
- unless item.is_a?(Proc) || item.respond_to?(:truthy?)
16
+ unless item.is_a?(Proc) || [item].flatten.all? { |it| it.respond_to?(:truthy?) }
17
17
  raise ArgumentError, "Object passed to only_if must respond_to 'truthy?'"
18
18
  end
19
19
  end
20
20
 
21
21
  prop_array(:not_if) do |item|
22
- unless item.is_a?(Proc) || item.respond_to?(:truthy?)
22
+ unless item.is_a?(Proc) || [item].flatten.all? { |it| it.respond_to?(:truthy?) }
23
23
  raise ArgumentError, "Object passed to not_if must respond_to 'truthy?'"
24
24
  end
25
25
  end
@@ -113,7 +113,7 @@ module OpenHAB
113
113
  # @return [Boolean] True if criteria are satisfied, false otherwise
114
114
  #
115
115
  def process_not_if(event, items, procs)
116
- items.none?(&:truthy?) && procs.none? { |proc| proc.call(event) }
116
+ items.flatten.none?(&:truthy?) && procs.none? { |proc| proc.call(event) }
117
117
  end
118
118
 
119
119
  #
@@ -126,7 +126,7 @@ module OpenHAB
126
126
  # @return [Boolean] True if criteria are satisfied, false otherwise
127
127
  #
128
128
  def process_only_if(event, items, procs)
129
- items.all?(&:truthy?) && procs.all? { |proc| proc.call(event) }
129
+ items.flatten.all?(&:truthy?) && procs.all? { |proc| proc.call(event) }
130
130
  end
131
131
  end
132
132
  end
@@ -31,18 +31,18 @@ module OpenHAB
31
31
  # @return [Trigger] OpenHAB trigger
32
32
  #
33
33
  def changed(*items, to: nil, from: nil, for: nil)
34
- separate_groups(items).each do |item|
34
+ separate_groups(items).map do |item|
35
35
  logger.trace("Creating changed trigger for entity(#{item}), to(#{to}), from(#{from})")
36
36
  # for is a reserved word in ruby, so use local_variable_get :for
37
37
  if (wait_duration = binding.local_variable_get(:for))
38
38
  changed_wait(item, to: to, from: from, duration: wait_duration)
39
39
  else
40
40
  # Place in array and flatten to support multiple to elements or single or nil
41
- [to].flatten.each do |to_state|
42
- [from].flatten.each { |from_state| create_changed_trigger(item, from_state, to_state) }
41
+ [to].flatten.map do |to_state|
42
+ [from].flatten.map { |from_state| create_changed_trigger(item, from_state, to_state) }
43
43
  end
44
44
  end
45
- end
45
+ end.flatten
46
46
  end
47
47
 
48
48
  private
@@ -55,12 +55,13 @@ module OpenHAB
55
55
  # @param [Item State] to OpenHAB Item State item or group needs to change to
56
56
  # @param [Item State] from OpenHAB Item State item or group needs to be coming from
57
57
  #
58
- # @return [Array] Array of current TriggerDelay objects
58
+ # @return [Trigger] OpenHAB trigger
59
59
  #
60
60
  def changed_wait(item, duration:, to: nil, from: nil)
61
61
  trigger = create_changed_trigger(item, nil, nil)
62
62
  logger.trace("Creating Changed Wait Change Trigger for #{item}")
63
63
  @trigger_delays[trigger.id] = TriggerDelay.new(to: to, from: from, duration: duration)
64
+ trigger
64
65
  end
65
66
 
66
67
  #
@@ -22,14 +22,14 @@ module OpenHAB
22
22
  #
23
23
  #
24
24
  def received_command(*items, command: nil, commands: nil)
25
- separate_groups(items).each do |item|
25
+ separate_groups(items).map do |item|
26
26
  logger.trace("Creating received command trigger for item(#{item})"\
27
27
  "command(#{command}) commands(#{commands})")
28
28
 
29
29
  # Combine command and commands, doing union so only a single nil will be in the combined array.
30
30
  combined_commands = combine_commands(command, commands)
31
31
  create_received_trigger(combined_commands, item)
32
- end
32
+ end.flatten
33
33
  end
34
34
 
35
35
  private
@@ -42,7 +42,7 @@ module OpenHAB
42
42
  #
43
43
  #
44
44
  def create_received_trigger(commands, item)
45
- commands.each do |command|
45
+ commands.map do |command|
46
46
  if item.is_a? OpenHAB::DSL::Items::GroupItem::GroupMembers
47
47
  config, trigger = create_group_command_trigger(item)
48
48
  else
@@ -10,9 +10,6 @@ module OpenHAB
10
10
  # Cron type rules
11
11
  #
12
12
  module Triggers
13
- java_import org.openhab.core.automation.util.TriggerBuilder
14
- java_import org.openhab.core.config.core.Configuration
15
-
16
13
  #
17
14
  # Returns a default map for cron expressions that fires every second
18
15
  # This map is usually updated via merge by other methods to refine cron type triggers.
@@ -20,13 +20,13 @@ module OpenHAB
20
20
  # @return [Trigger] Trigger for updated entity
21
21
  #
22
22
  def updated(*items, to: nil)
23
- separate_groups(items).each do |item|
23
+ separate_groups(items).map do |item|
24
24
  logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
25
- [to].flatten.each do |to_state|
25
+ [to].flatten.map do |to_state|
26
26
  trigger, config = create_update_trigger(item, to_state)
27
27
  append_trigger(trigger, config)
28
28
  end
29
- end
29
+ end.flatten
30
30
  end
31
31
 
32
32
  private
@@ -47,7 +47,7 @@ module OpenHAB
47
47
 
48
48
  private
49
49
 
50
- java_import 'org.openhab.core.automation.annotation.RuleAction'
50
+ java_import org.openhab.core.automation.annotation.RuleAction
51
51
 
52
52
  #
53
53
  # Define methods from actions mapped to this thing
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.8.2'
8
+ VERSION = '4.9.0'
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.2
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-30 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler