openhab-scripting 4.8.0 → 4.8.4

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: 59b0441f0cce1fb707bfb5d74d051135ce37c63128359cfa98cdae2573b920d2
4
- data.tar.gz: 0101f396a6bce5e6d52f3191973fb6db2f3cb3be93f00229b4cc5297f04488bf
3
+ metadata.gz: 85403da3b59930bb61a16e74f658e2257209c13a962d4f66a7ab4167a382f48b
4
+ data.tar.gz: 75e19bdace713e9386828cf9e3be1e21000314d7d774cc703a1ae62141f93222
5
5
  SHA512:
6
- metadata.gz: ac154dd9d98ca0305c30770286554cb0b4bc863f1af95e7e03a32090aac7cc8f13633a42d2bcd8da7bc8b585f377a4db74d8a4ef668675ac0704fed9627f9973
7
- data.tar.gz: bc241f0713e34124057fb124658dd13b4437bbe455bbf975c616aefd6a05b49a8d224039e23175dd7c1c350a17fa782eec2c8d22748e56f24cf8e618774396a2
6
+ metadata.gz: d4a975ad351673ff58f1e8cf43b86bc5002fdb036217a70a8ff2e7c1351eca827544319f4ebbcd50939c8eda4679d2aa3516c41f1e8edb4f1912798e3f1708a3
7
+ data.tar.gz: f48db351969332ea07d8b8bfb2c2b538e247427dae3124d3b1c76cf29d6c2adee498eefd0c40b913b9f76db3ebc95993469b3bd13d2e5e91862352d002fafe11
@@ -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
  #
@@ -21,7 +21,7 @@ module OpenHAB
21
21
  #
22
22
  #
23
23
  def update_from_file(file, mime_type: nil)
24
- file_data = IO.binread(file)
24
+ file_data = File.binread(file)
25
25
  mime_type ||= Marcel::MimeType.for(Pathname.new(file)) || Marcel::MimeType.for(file_data)
26
26
  update_from_bytes(file_data, mime_type: mime_type)
27
27
  end
@@ -77,7 +77,6 @@ module OpenHAB
77
77
  # Create the run queue based on guards
78
78
  #
79
79
  # @param [Map] inputs rule inputs
80
- #
81
80
  # @return [Queue] <description>
82
81
  #
83
82
  def create_queue(inputs)
@@ -243,6 +242,8 @@ module OpenHAB
243
242
  #
244
243
  # @return [Boolean] True if guards says rule should execute, false otherwise
245
244
  #
245
+ # rubocop:disable Metrics/MethodLength
246
+ # Loggging inflates method length
246
247
  def check_guards(event:)
247
248
  if @guard.should_run? event
248
249
  now = TimeOfDay::TimeOfDay.now
@@ -254,7 +255,10 @@ module OpenHAB
254
255
  logger.trace("Skipped execution of rule '#{name}' because of guard #{@guard}")
255
256
  end
256
257
  false
258
+ rescue StandardError => e
259
+ print_backtrace(e)
257
260
  end
261
+ # rubocop:enable Metrics/MethodLength
258
262
 
259
263
  #
260
264
  # Process the run queue
@@ -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
@@ -78,7 +78,7 @@ module OpenHAB
78
78
  args[0] = if hue.is_a?(DecimalType)
79
79
  hue
80
80
  elsif hue.is_a?(QuantityType)
81
- DecimalType.new(hue.to_unit(::Units::DEGREE_ANGLE).to_big_decimal)
81
+ DecimalType.new(hue.to_unit(org.openhab.core.library.unit.Units::DEGREE_ANGLE).to_big_decimal)
82
82
  elsif hue.respond_to?(:to_d)
83
83
  DecimalType.new(hue)
84
84
  end
@@ -150,7 +150,7 @@ module OpenHAB
150
150
  # @!attribute [r] hue
151
151
  # @return [QuantityType]
152
152
  def hue
153
- QuantityType.new(raw_hue.to_big_decimal, ::Units::DEGREE_ANGLE)
153
+ QuantityType.new(raw_hue.to_big_decimal, org.openhab.core.library.unit.Units::DEGREE_ANGLE)
154
154
  end
155
155
 
156
156
  # Convert to a packed 32-bit RGB value representing the color in the default sRGB color model.
@@ -73,7 +73,7 @@ module OpenHAB
73
73
  return error if debug_enabled?
74
74
 
75
75
  if error.respond_to? :backtrace_locations
76
- backtrace = error.backtrace_locations.map(&:to_s).reject { |line| INTERNAL_CALL_REGEX.match? line }
76
+ backtrace = error.backtrace_locations.map(&:to_s).grep_v(INTERNAL_CALL_REGEX)
77
77
  error.set_backtrace(backtrace)
78
78
  elsif error.respond_to? :stack_trace
79
79
  backtrace = error.stack_trace.reject { |line| JAVA_INTERNAL_CALL_REGEX.match? line.to_s }
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.8.0'
8
+ VERSION = '4.8.4'
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.0
4
+ version: 4.8.4
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-29 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