openhab-scripting 4.26.4 → 4.28.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/entity_lookup.rb +3 -1
- data/lib/openhab/core/item_proxy.rb +29 -0
- data/lib/openhab/dsl/items/ensure.rb +5 -1
- data/lib/openhab/dsl/items/generic_item.rb +8 -1
- data/lib/openhab/dsl/items/items.rb +0 -2
- data/lib/openhab/dsl/rules/automation_rule.rb +2 -12
- data/lib/openhab/dsl/rules/rule.rb +4 -15
- data/lib/openhab/dsl/states.rb +3 -1
- data/lib/openhab/dsl/timers/manager.rb +14 -1
- data/lib/openhab/dsl/types/date_time_type.rb +2 -2
- data/lib/openhab/dsl/types/decimal_type.rb +1 -1
- data/lib/openhab/dsl/types/hsb_type.rb +1 -1
- data/lib/openhab/dsl/types/increase_decrease_type.rb +1 -1
- data/lib/openhab/dsl/types/next_previous_type.rb +1 -1
- data/lib/openhab/dsl/types/on_off_type.rb +1 -1
- data/lib/openhab/dsl/types/open_closed_type.rb +1 -1
- data/lib/openhab/dsl/types/percent_type.rb +1 -1
- data/lib/openhab/dsl/types/play_pause_type.rb +1 -1
- data/lib/openhab/dsl/types/point_type.rb +1 -1
- data/lib/openhab/dsl/types/quantity_type.rb +1 -1
- data/lib/openhab/dsl/types/refresh_type.rb +1 -1
- data/lib/openhab/dsl/types/rewind_fastforward_type.rb +1 -1
- data/lib/openhab/dsl/types/stop_move_type.rb +1 -1
- data/lib/openhab/dsl/types/string_type.rb +1 -1
- data/lib/openhab/dsl/types/un_def_type.rb +1 -1
- data/lib/openhab/dsl/types/up_down_type.rb +1 -1
- data/lib/openhab/log/configuration.rb +1 -1
- data/lib/openhab/log/logger.rb +10 -0
- data/lib/openhab/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 824e2af85aba6737c05884f3f6ca06adc1873a388b8091062781b274290c6476
|
4
|
+
data.tar.gz: 159ed6ce10d55640c37b61429a937f4dafaecf529479b3423552bff9d929d30d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
#
|
data/lib/openhab/dsl/states.rb
CHANGED
@@ -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] =
|
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
|
-
|
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
|
-
|
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
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OpenHAB
|
4
4
|
module DSL
|
5
5
|
module Types
|
6
|
-
|
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
|
-
|
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
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OpenHAB
|
4
4
|
module DSL
|
5
5
|
module Types
|
6
|
-
|
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
|
-
|
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
|
@@ -7,7 +7,7 @@ require_relative 'comparable_type'
|
|
7
7
|
module OpenHAB
|
8
8
|
module DSL
|
9
9
|
module Types
|
10
|
-
|
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
|
data/lib/openhab/log/logger.rb
CHANGED
@@ -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
|
#
|
data/lib/openhab/version.rb
CHANGED
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.
|
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-
|
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
|