openhab-scripting 4.26.4 → 4.28.1

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: cd63a855a2b36bd98bbec644125c3d3969b5de15c34a6a068c1569be78af7df7
4
- data.tar.gz: 742a8bc187187d0b3efec387286781464567bb87e77723b7c46a97fa5f5b3f82
3
+ metadata.gz: 824e2af85aba6737c05884f3f6ca06adc1873a388b8091062781b274290c6476
4
+ data.tar.gz: 159ed6ce10d55640c37b61429a937f4dafaecf529479b3423552bff9d929d30d
5
5
  SHA512:
6
- metadata.gz: 7b70022cd9e0fdcc545611ca0a36b5a6122884b8cccfa1f1992cbec7b1d19b24cb86fa55e127b258500c318090dbf0bb9009d3916d32d61c0c2ca3f2e0edb290
7
- data.tar.gz: cd6bcd955c3c853bc6e52cdd999e096ca5ecc78bbd61f1db4ff9426395220fe9156a8f458deee0637f85e1c6dc27f2e7b74c8835c2c984d84f2baa92c4a9eb65
6
+ metadata.gz: 3f6f18504814c73aad6e9c5d5a7548ae17165dff3d4f85a618103f79574389d201c82a528ec09b27b37e975b05b47bb0cd78e958ba0a4bb3b094314f842b9c0e
7
+ data.tar.gz: d0baf3b51e76656b68e24faa3ceb8d0e76e6afea89b2ba6f81c152ce0f2ddb560fe1942af225f8f1b7ace9c5d3e9c1605c83a1654bddecdceb16f57d47c93b6e
@@ -5,6 +5,7 @@ require 'java'
5
5
  require 'set'
6
6
 
7
7
  require 'openhab/log/logger'
8
+ require_relative 'item_proxy'
8
9
 
9
10
  # Automation lookup and injection of OpenHab entities
10
11
 
@@ -91,7 +92,8 @@ module OpenHAB
91
92
  def self.lookup_item(name)
92
93
  logger.trace("Looking up item(#{name})")
93
94
  name = name.to_s if name.is_a? Symbol
94
- $ir.get(name) # rubocop: disable Style/GlobalVars
95
+ item = $ir.get(name) # rubocop: disable Style/GlobalVars
96
+ ItemProxy.new(item) unless item.nil?
95
97
  end
96
98
  end
97
99
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+ require 'forwardable'
5
+
6
+ module OpenHAB
7
+ module Core
8
+ # Class is a proxy to underlying item
9
+ class ItemProxy < Delegator
10
+ extend Forwardable
11
+ def_delegators :__getobj__, :class, :is_a?, :kind_of?, :instance_of?
12
+
13
+ #
14
+ # Set the proxy item (called by super)
15
+ #
16
+ def __setobj__(item)
17
+ # Convert name to java version for faster lookups
18
+ @item_name = item.name.to_java
19
+ end
20
+
21
+ #
22
+ # Lookup item from item registry
23
+ #
24
+ def __getobj__
25
+ $ir.get(@item_name) # rubocop:disable Style/GlobalVars
26
+ end
27
+ end
28
+ end
29
+ end
@@ -53,7 +53,11 @@ module OpenHAB
53
53
  # sending the command
54
54
  def command(command)
55
55
  return super unless Thread.current[:ensure_states]
56
- return if command == state
56
+
57
+ logger.trace do
58
+ "#{name} ensure #{command}, format_type_pre: #{format_type_pre(command)}, current state: #{state}"
59
+ end
60
+ return if state == format_type_pre(command)
57
61
 
58
62
  super
59
63
  end
@@ -33,6 +33,13 @@ module OpenHAB
33
33
  def ACCEPTED_DATA_TYPES
34
34
  [org.openhab.core.types.UnDefType.java_class].freeze
35
35
  end
36
+
37
+ #
38
+ # Override to support ItemProxy
39
+ #
40
+ def ===(other)
41
+ other.instance_of?(self)
42
+ end
36
43
  end
37
44
  # rubocop:enable Naming/MethodName
38
45
 
@@ -128,7 +135,7 @@ module OpenHAB
128
135
  # @return [Array<Group>] All groups that this item is part of
129
136
  #
130
137
  def groups
131
- group_names.map { |name| Groups.groups[name] }
138
+ group_names.map { |name| Groups.groups[name] }.compact
132
139
  end
133
140
 
134
141
  # Return the item's thing if this item is linked with a thing. If an item is linked to more than one thing,
@@ -6,11 +6,9 @@ require 'openhab/dsl/types/types'
6
6
  require_relative 'item_registry'
7
7
 
8
8
  require_relative 'generic_item'
9
-
10
9
  require_relative 'switch_item'
11
10
  require_relative 'date_time_item'
12
11
  require_relative 'dimmer_item'
13
-
14
12
  require_relative 'color_item'
15
13
  require_relative 'contact_item'
16
14
  require_relative 'group_item'
@@ -304,7 +304,7 @@ module OpenHAB
304
304
  end
305
305
  false
306
306
  rescue StandardError => e
307
- print_backtrace(e)
307
+ logger.log_exception(e, name)
308
308
  end
309
309
  # rubocop:enable Metrics/MethodLength
310
310
 
@@ -328,7 +328,7 @@ module OpenHAB
328
328
  end
329
329
  end
330
330
  rescue StandardError => e
331
- print_backtrace(e)
331
+ logger.log_exception(e, name)
332
332
  end
333
333
 
334
334
  #
@@ -399,16 +399,6 @@ module OpenHAB
399
399
  @run_context.instance_exec(event, &task.block)
400
400
  end
401
401
 
402
- #
403
- # Print error and stack trace without calls to internal classes
404
- #
405
- # @param [Exception] error A rescued error
406
- #
407
- def print_backtrace(error)
408
- error = logger.clean_backtrace(error)
409
- logger.error { "#{error.message} (#{error.class})\nIn rule: #{name}\n#{error.backtrace&.join("\n")}" }
410
- end
411
-
412
402
  #
413
403
  # Create a new hash in which all elements are converted to strings
414
404
  #
@@ -26,7 +26,7 @@ module OpenHAB
26
26
  @registry = OpenHAB::Core.rule_registry
27
27
  class << self
28
28
  attr_reader :script_rules, :automation_manager, :registry
29
- end
29
+ end
30
30
 
31
31
  #
32
32
  # Create a new rule
@@ -35,7 +35,7 @@ end
35
35
  # @yield [] Block executed in context of a RuleConfig
36
36
  #
37
37
  #
38
- # rubocop: disable Metrics
38
+ # rubocop: disable Metrics/MethodLength
39
39
  def rule(rule_name, &block)
40
40
  thread_local(RULE_NAME: rule_name) do
41
41
  @rule_name = rule_name
@@ -47,10 +47,9 @@ end
47
47
  nil # Must return something other than the rule object. See https://github.com/boc-tothefuture/openhab-jruby/issues/438
48
48
  end
49
49
  rescue StandardError => e
50
- puts "#{e.class}: #{e.message}"
51
- re_raise_with_backtrace(e)
50
+ logger.log_exception(e, @rule_name)
52
51
  end
53
- # rubocop: enable Metrics
52
+ # rubocop: enable Metrics/MethodLength
54
53
 
55
54
  #
56
55
  # Cleanup rules in this script file
@@ -62,16 +61,6 @@ end
62
61
 
63
62
  private
64
63
 
65
- #
66
- # Re-raises a rescued error to OpenHAB with added rule name and stack trace
67
- #
68
- # @param [Exception] error A rescued error
69
- #
70
- def re_raise_with_backtrace(error)
71
- error = logger.clean_backtrace(error)
72
- raise error, "#{error.message}\nIn rule: #{@rule_name}\n#{error.backtrace.join("\n")}"
73
- end
74
-
75
64
  #
76
65
  # Process a rule based on the supplied configuration
77
66
  #
@@ -48,7 +48,9 @@ module OpenHAB
48
48
  # @return [StateStorage] item states
49
49
  #
50
50
  def store_states(*items)
51
- items = items.flatten
51
+ items = items.flatten.map do |item|
52
+ item.respond_to?(:__getobj__) ? item.__getobj__ : item
53
+ end
52
54
  states = StateStorage.new(BusEvent.storeStates(*items).to_h)
53
55
  if block_given?
54
56
  yield
@@ -39,7 +39,7 @@ module OpenHAB
39
39
 
40
40
  if timer.respond_to? :id
41
41
  logger.trace("Adding #{timer} with id #{timer.id.inspect} timer ids")
42
- @timer_ids[timer.id] = Set.new unless @timer_ids[timer.id]
42
+ @timer_ids[timer.id] = TimerSet.new unless @timer_ids[timer.id]
43
43
  @timer_ids[timer.id] << timer
44
44
  end
45
45
 
@@ -87,6 +87,19 @@ module OpenHAB
87
87
  @timers.clear
88
88
  end
89
89
  end
90
+
91
+ #
92
+ # Provide additional methods for the timers set
93
+ #
94
+ class TimerSet < Set
95
+ #
96
+ # A shorthand to cancel all the timer objects held within the set
97
+ # so that timers[timer_id].cancel_all is equivalent to timers[timer_id].each(&:cancel)
98
+ #
99
+ def cancel_all
100
+ each(&:cancel)
101
+ end
102
+ end
90
103
  end
91
104
  end
92
105
  end
@@ -7,8 +7,8 @@ require 'java'
7
7
  module OpenHAB
8
8
  module DSL
9
9
  module Types
10
- java_import org.openhab.core.library.types.DateTimeType
11
- java_import java.time.ZonedDateTime
10
+ DateTimeType = org.openhab.core.library.types.DateTimeType
11
+ java_import java.time.ZonedDateTime # This is needed for the addon prior to ruby_class fix (OH 3.2.0)
12
12
 
13
13
  # global alias
14
14
  ::DateTimeType = DateTimeType
@@ -6,7 +6,7 @@ require_relative 'numeric_type'
6
6
  module OpenHAB
7
7
  module DSL
8
8
  module Types
9
- java_import org.openhab.core.library.types.DecimalType
9
+ DecimalType = org.openhab.core.library.types.DecimalType
10
10
 
11
11
  #
12
12
  # Add methods to core OpenHAB DecimalType to make it behave as a Ruby
@@ -6,7 +6,7 @@ require_relative 'percent_type'
6
6
  module OpenHAB
7
7
  module DSL
8
8
  module Types
9
- java_import org.openhab.core.library.types.HSBType
9
+ HSBType = org.openhab.core.library.types.HSBType
10
10
 
11
11
  # global alias
12
12
  ::HSBType = HSBType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.IncreaseDecreaseType
6
+ IncreaseDecreaseType = org.openhab.core.library.types.IncreaseDecreaseType
7
7
 
8
8
  # Adds methods to core OpenHAB IncreaseDecreaseType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.NextPreviousType
6
+ NextPreviousType = org.openhab.core.library.types.NextPreviousType
7
7
 
8
8
  # Adds methods to core OpenHAB NextPreviousType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.OnOffType
6
+ OnOffType = org.openhab.core.library.types.OnOffType
7
7
 
8
8
  # Adds methods to core OpenHAB OnOffType to make it more natural in Ruby
9
9
  class OnOffType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.OpenClosedType
6
+ OpenClosedType = org.openhab.core.library.types.OpenClosedType
7
7
 
8
8
  # Adds methods to core OpenHAB OpenClosedType to make it more natural in Ruby
9
9
  class OpenClosedType
@@ -5,7 +5,7 @@ require_relative 'decimal_type'
5
5
  module OpenHAB
6
6
  module DSL
7
7
  module Types
8
- java_import org.openhab.core.library.types.PercentType
8
+ PercentType = org.openhab.core.library.types.PercentType
9
9
 
10
10
  # global alias
11
11
  ::PercentType = PercentType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.PlayPauseType
6
+ PlayPauseType = org.openhab.core.library.types.PlayPauseType
7
7
 
8
8
  # Adds methods to core OpenHAB PlayPauseType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.PointType
6
+ PointType = org.openhab.core.library.types.PointType
7
7
 
8
8
  # global scope
9
9
  # @!visibility private
@@ -5,7 +5,7 @@ require_relative 'numeric_type'
5
5
  module OpenHAB
6
6
  module DSL
7
7
  module Types
8
- java_import org.openhab.core.library.types.QuantityType
8
+ QuantityType = org.openhab.core.library.types.QuantityType
9
9
 
10
10
  # global alias
11
11
  ::QuantityType = QuantityType
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.types.RefreshType
6
+ RefreshType = org.openhab.core.types.RefreshType
7
7
 
8
8
  # Adds methods to core OpenHAB RefreshType to make it more natural in Ruby
9
9
  class RefreshType # rubocop:disable Lint/EmptyClass
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.RewindFastforwardType
6
+ RewindFastforwardType = org.openhab.core.library.types.RewindFastforwardType
7
7
 
8
8
  # Adds methods to core OpenHAB RewindFastforwardType to make it more
9
9
  # natural in Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.StopMoveType
6
+ StopMoveType = org.openhab.core.library.types.StopMoveType
7
7
 
8
8
  # Adds methods to core OpenHAB StopMoveType to make it more
9
9
  # natural in Ruby
@@ -7,7 +7,7 @@ require_relative 'comparable_type'
7
7
  module OpenHAB
8
8
  module DSL
9
9
  module Types
10
- java_import org.openhab.core.library.types.StringType
10
+ StringType = org.openhab.core.library.types.StringType
11
11
 
12
12
  #
13
13
  # Add methods to core OpenHAB StringType to make it behave as a Ruby
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.types.UnDefType
6
+ UnDefType = org.openhab.core.types.UnDefType
7
7
 
8
8
  # Adds methods to core OpenHAB UnDefType to make it more natural in Ruby
9
9
  class UnDefType # rubocop:disable Lint/EmptyClass
@@ -3,7 +3,7 @@
3
3
  module OpenHAB
4
4
  module DSL
5
5
  module Types
6
- java_import org.openhab.core.library.types.UpDownType
6
+ UpDownType = org.openhab.core.library.types.UpDownType
7
7
 
8
8
  # Adds methods to core OpenHAB UpDownType to make it more natural in Ruby
9
9
  class UpDownType
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  # This module holds global configuration values
7
7
  module Configuration
8
8
  # -*- coding: utf-8 -*-
9
- LOG_PREFIX = 'jsr223.jruby'
9
+ LOG_PREFIX = 'org.openhab.automation.jruby'
10
10
 
11
11
  #
12
12
  # Gets the log prefix
@@ -82,6 +82,16 @@ module OpenHAB
82
82
  error
83
83
  end
84
84
 
85
+ #
86
+ # Print error and stack trace without calls to internal classes
87
+ #
88
+ # @param [Exception] error A rescued error
89
+ #
90
+ def log_exception(exception, rule_name)
91
+ exception = clean_backtrace(exception)
92
+ error { "#{exception.message} (#{exception.class})\nIn rule: #{rule_name}\n#{exception.backtrace&.join("\n")}" }
93
+ end
94
+
85
95
  private
86
96
 
87
97
  #
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.26.4'
8
+ VERSION = '4.28.1'
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.26.4
4
+ version: 4.28.1
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: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - lib/openhab.rb
49
49
  - lib/openhab/core/entity_lookup.rb
50
+ - lib/openhab/core/item_proxy.rb
50
51
  - lib/openhab/core/load_path.rb
51
52
  - lib/openhab/core/openhab_setup.rb
52
53
  - lib/openhab/core/osgi.rb