openhab-scripting 5.44.1 → 5.46.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 +4 -4
- data/lib/openhab/core/actions/notification.rb +11 -14
- data/lib/openhab/core/actions/transformation.rb +1 -1
- data/lib/openhab/core/actions/voice.rb +1 -1
- data/lib/openhab/core/actions.rb +2 -2
- data/lib/openhab/core/entity_lookup.rb +2 -2
- data/lib/openhab/core/events/item_state_changed_event.rb +2 -3
- data/lib/openhab/core/gem.rb +17 -0
- data/lib/openhab/core/items/persistence.rb +10 -40
- data/lib/openhab/core/items/registry.rb +2 -2
- data/lib/openhab/core/items/semantics/enumerable.rb +4 -4
- data/lib/openhab/core/items/semantics.rb +0 -6
- data/lib/openhab/core/items.rb +5 -5
- data/lib/openhab/core/lazy_array.rb +2 -2
- data/lib/openhab/core/things/registry.rb +2 -2
- data/lib/openhab/core/types/date_time_type.rb +10 -34
- data/lib/openhab/core/types/hsb_type.rb +2 -2
- data/lib/openhab/core/types.rb +29 -29
- data/lib/openhab/core.rb +8 -2
- data/lib/openhab/core_ext/java/duration.rb +1 -1
- data/lib/openhab/core_ext/java/list.rb +4 -4
- data/lib/openhab/core_ext/ruby/symbol.rb +1 -1
- data/lib/openhab/dsl/config_description/builder.rb +24 -20
- data/lib/openhab/dsl/items/builder.rb +7 -7
- data/lib/openhab/dsl/items/timed_command.rb +5 -5
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +3 -3
- data/lib/openhab/dsl/sitemaps/builder.rb +40 -65
- data/lib/openhab/dsl/things/builder.rb +8 -8
- data/lib/openhab/dsl/timer_manager.rb +0 -1
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +21 -21
- data/lib/openhab/rspec/helpers.rb +11 -13
- data/lib/openhab/rspec/karaf.rb +4 -4
- data/lib/openhab/rspec/mocks/timer.rb +2 -2
- metadata +32 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6351743424c867636542a49ecdb2ef2eca63824d2009ae517763d256f7fab20
|
|
4
|
+
data.tar.gz: 72d778a25df32f555763c38539c1bb7d34ae2f24c70120d069504d18e036eaac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6d35c4a0489003faeabf001e3215bb8f4e9e805cdffb69ba0b10d9261127f08f07f1c0e61cc072ff849eab6dc70c88d9b11003c9f830c53e93ff92ce5ae03ce
|
|
7
|
+
data.tar.gz: 0be0d9f6149485518eabb0b4c08bb4a73ce7fdf7c9d231e9c9ee590f132a74f647dcbb4c3e3d1087dd2be10a1f487736e45214af2037e2093f019de3d3aeadda
|
|
@@ -91,22 +91,19 @@ module OpenHAB
|
|
|
91
91
|
tag ||= severity
|
|
92
92
|
args.push(msg.to_s, icon&.to_s, tag&.to_s)
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
buttons = buttons.map { |button_title, action| "#{button_title}=#{action}" } if buttons.is_a?(Hash)
|
|
98
|
-
raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(buttons.size)
|
|
94
|
+
buttons ||= []
|
|
95
|
+
buttons = buttons.map { |button_title, action| "#{button_title}=#{action}" } if buttons.is_a?(Hash)
|
|
96
|
+
raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(buttons.size)
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
attachment = "item:#{attachment.name}" if attachment.is_a?(Item) && attachment.image_item?
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
100
|
+
args.push(title&.to_s,
|
|
101
|
+
id&.to_s,
|
|
102
|
+
on_click&.to_s,
|
|
103
|
+
attachment&.to_s,
|
|
104
|
+
buttons[0]&.to_s,
|
|
105
|
+
buttons[1]&.to_s,
|
|
106
|
+
buttons[2]&.to_s)
|
|
110
107
|
|
|
111
108
|
NotificationAction.__send__(*args)
|
|
112
109
|
end
|
|
@@ -7,7 +7,7 @@ module OpenHAB
|
|
|
7
7
|
class Transformation
|
|
8
8
|
class << self
|
|
9
9
|
# @!visibility private
|
|
10
|
-
alias_method :raw_transform, :transform if
|
|
10
|
+
alias_method :raw_transform, :transform if method_defined?(:transform)
|
|
11
11
|
|
|
12
12
|
#
|
|
13
13
|
# Applies a transformation of a given type with some function to a value.
|
data/lib/openhab/core/actions.rb
CHANGED
|
@@ -53,9 +53,9 @@ module OpenHAB
|
|
|
53
53
|
# @!method notify(msg, email: nil, icon: nil, tag: nil, severity: nil, id: nil, title: nil, on_click: nil, attachment: nil, buttons: nil)
|
|
54
54
|
# @deprecated Use {Notification.send Notification.send} instead.
|
|
55
55
|
#
|
|
56
|
-
def notify(
|
|
56
|
+
def notify(*, **)
|
|
57
57
|
logger.warn("`notify` method is deprecated. Use `Notification.send` instead.")
|
|
58
|
-
Notification.send(
|
|
58
|
+
Notification.send(*, **)
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
|
@@ -137,9 +137,9 @@ module OpenHAB
|
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
# @!visibility private
|
|
140
|
-
def instance_eval_with_dummy_items(&
|
|
140
|
+
def instance_eval_with_dummy_items(&)
|
|
141
141
|
DSL::ThreadLocal.thread_local(openhab_create_dummy_items: self.class.create_dummy_items?) do
|
|
142
|
-
instance_eval(&
|
|
142
|
+
instance_eval(&)
|
|
143
143
|
end
|
|
144
144
|
end
|
|
145
145
|
|
|
@@ -82,9 +82,8 @@ module OpenHAB
|
|
|
82
82
|
def inspect
|
|
83
83
|
s = "#<OpenHAB::Core::Events::ItemStateChangedEvent item=#{item_name} " \
|
|
84
84
|
"state=#{item_state.inspect} was=#{old_item_state.inspect}"
|
|
85
|
-
|
|
86
|
-
s += "
|
|
87
|
-
s += " last_state_change=#{last_state_change}" if respond_to?(:last_state_change) && last_state_change
|
|
85
|
+
s += " last_state_update=#{last_state_update}" if last_state_update
|
|
86
|
+
s += " last_state_change=#{last_state_change}" if last_state_change
|
|
88
87
|
s += " source=#{source.inspect}" if source
|
|
89
88
|
"#{s}>"
|
|
90
89
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
openhab_spec = Gem::Specification.new do |s|
|
|
4
|
+
s.name = "openhab"
|
|
5
|
+
s.version = -(ENV["OPENHAB_VERSION"] || "5.1.0")
|
|
6
|
+
|
|
7
|
+
def s.deleted_gem?
|
|
8
|
+
false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def s.installation_missing?
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Gem::Specification.add_spec(openhab_spec)
|
|
17
|
+
Gem.post_reset { Gem::Specification.add_spec(openhab_spec) }
|
|
@@ -670,15 +670,6 @@ module OpenHAB
|
|
|
670
670
|
# @since openHAB 4.2
|
|
671
671
|
#
|
|
672
672
|
def persist(*args)
|
|
673
|
-
# @deprecated OH 4.1 this if block content can be removed when dropping OH 4.1 support
|
|
674
|
-
if Core.version < Core::V4_2
|
|
675
|
-
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..1)" if args.size > 1
|
|
676
|
-
|
|
677
|
-
service = args.last || persistence_service
|
|
678
|
-
Actions::PersistenceExtensions.persist(self, service&.to_s)
|
|
679
|
-
return
|
|
680
|
-
end
|
|
681
|
-
|
|
682
673
|
first_arg = args.first
|
|
683
674
|
if first_arg.is_a?(TimeSeries)
|
|
684
675
|
if args.size > 2
|
|
@@ -752,9 +743,6 @@ module OpenHAB
|
|
|
752
743
|
# @since openHAB 4.2
|
|
753
744
|
|
|
754
745
|
%i[last_update next_update last_change next_change].each do |method|
|
|
755
|
-
# @deprecated OH 4.1 remove this guard when dropping OH 4.1
|
|
756
|
-
next unless Actions::PersistenceExtensions.respond_to?(method)
|
|
757
|
-
|
|
758
746
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
759
747
|
def #{method}(service = nil) # def last_update(service = nil)
|
|
760
748
|
service ||= persistence_service # service ||= persistence_service
|
|
@@ -794,9 +782,6 @@ module OpenHAB
|
|
|
794
782
|
# @since openHAB 4.2
|
|
795
783
|
|
|
796
784
|
%i[previous_state next_state].each do |method|
|
|
797
|
-
# @deprecated OH 4.1 remove this guard when dropping OH 4.1
|
|
798
|
-
next unless Actions::PersistenceExtensions.respond_to?(method)
|
|
799
|
-
|
|
800
785
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
801
786
|
def #{method}(service = nil, skip_equal: false) # def previous_state(service = nil, skip_equal: false)
|
|
802
787
|
service ||= persistence_service # service ||= persistence_service
|
|
@@ -819,10 +804,7 @@ module OpenHAB
|
|
|
819
804
|
|
|
820
805
|
if riemann_param
|
|
821
806
|
riemann_param = ", riemann_type: nil"
|
|
822
|
-
|
|
823
|
-
if Actions::PersistenceExtensions.const_defined?(:RiemannType)
|
|
824
|
-
riemann_arg = "to_riemann_type(riemann_type),"
|
|
825
|
-
end
|
|
807
|
+
riemann_arg = "to_riemann_type(riemann_type),"
|
|
826
808
|
end
|
|
827
809
|
|
|
828
810
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
@@ -846,17 +828,11 @@ module OpenHAB
|
|
|
846
828
|
riemann_arg = nil
|
|
847
829
|
|
|
848
830
|
def_persistence_method("#{method}_since#{suffix}", quantify:, riemann_param:)
|
|
849
|
-
#
|
|
850
|
-
if OpenHAB::Core.version >= OpenHAB::Core::V4_2
|
|
851
|
-
def_persistence_method("#{method}_until#{suffix}", quantify:, riemann_param:)
|
|
852
|
-
end
|
|
831
|
+
def_persistence_method("#{method}_until#{suffix}", quantify:, riemann_param:)
|
|
853
832
|
|
|
854
833
|
if riemann_param
|
|
855
834
|
riemann_param = ", riemann_type: nil"
|
|
856
|
-
|
|
857
|
-
if Actions::PersistenceExtensions.const_defined?(:RiemannType)
|
|
858
|
-
riemann_arg = "to_riemann_type(riemann_type),"
|
|
859
|
-
end
|
|
835
|
+
riemann_arg = "to_riemann_type(riemann_type),"
|
|
860
836
|
end
|
|
861
837
|
|
|
862
838
|
method = "#{method}_between"
|
|
@@ -889,7 +865,7 @@ module OpenHAB
|
|
|
889
865
|
|
|
890
866
|
def_persistence_methods(:count_state_changes)
|
|
891
867
|
alias_method :state_changes_since, :count_state_changes_since
|
|
892
|
-
alias_method :state_changes_until, :count_state_changes_until
|
|
868
|
+
alias_method :state_changes_until, :count_state_changes_until
|
|
893
869
|
alias_method :state_changes_between, :count_state_changes_between
|
|
894
870
|
|
|
895
871
|
def_persistence_methods(:delta, quantify: true)
|
|
@@ -900,27 +876,21 @@ module OpenHAB
|
|
|
900
876
|
|
|
901
877
|
def_persistence_methods(:get_all_states, quantify: true)
|
|
902
878
|
alias_method :all_states_since, :get_all_states_since
|
|
903
|
-
alias_method :all_states_until, :get_all_states_until
|
|
879
|
+
alias_method :all_states_until, :get_all_states_until
|
|
904
880
|
alias_method :all_states_between, :get_all_states_between
|
|
905
881
|
|
|
906
882
|
def_persistence_methods(:maximum, quantify: true)
|
|
907
883
|
def_persistence_methods(:minimum, quantify: true)
|
|
908
|
-
def_persistence_methods(:median, quantify: true)
|
|
909
|
-
|
|
910
|
-
if Actions::PersistenceExtensions.const_defined?(:RiemannType)
|
|
911
|
-
# riemann_sum methods were added in OH 5.0 which already quantifies the result in core
|
|
912
|
-
def_persistence_methods(:riemann_sum, riemann_param: true)
|
|
913
|
-
end
|
|
884
|
+
def_persistence_methods(:median, quantify: true)
|
|
885
|
+
def_persistence_methods(:riemann_sum, riemann_param: true) # already quantified in core
|
|
914
886
|
def_persistence_methods(:sum, quantify: true)
|
|
915
887
|
def_persistence_methods(:updated?)
|
|
916
888
|
def_persistence_methods(:variance, quantify: true, riemann_param: true)
|
|
917
889
|
|
|
918
|
-
|
|
919
|
-
def_persistence_method(:persisted_state) # already quantified in core
|
|
890
|
+
def_persistence_method(:persisted_state) # already quantified in core
|
|
920
891
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
end
|
|
892
|
+
def_persistence_methods(:evolution_rate)
|
|
893
|
+
def_persistence_methods(:remove_all_states)
|
|
924
894
|
|
|
925
895
|
# @deprecated OH 4.2 this method is deprecated in OH 4.2 and may be removed in a future version
|
|
926
896
|
def evolution_rate(start, finish_or_service = nil, service = nil)
|
|
@@ -52,9 +52,9 @@ module OpenHAB
|
|
|
52
52
|
#
|
|
53
53
|
# @see DSL::Items::Builder DSL::Items::Builder for more details and examples
|
|
54
54
|
#
|
|
55
|
-
def build(preferred_provider = nil, update: true, &
|
|
55
|
+
def build(preferred_provider = nil, update: true, &)
|
|
56
56
|
DSL::Items::BaseBuilderDSL.new(preferred_provider, update:)
|
|
57
|
-
.instance_eval_with_dummy_items(&
|
|
57
|
+
.instance_eval_with_dummy_items(&)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
#
|
|
@@ -97,16 +97,16 @@ module Enumerable
|
|
|
97
97
|
# Send a command to every item in the collection
|
|
98
98
|
# @return [self, nil] nil when `ensure` is in effect and all the items were already in the same state,
|
|
99
99
|
# otherwise self
|
|
100
|
-
def command(command, **
|
|
101
|
-
self if count { |i| i.command(command, **
|
|
100
|
+
def command(command, **)
|
|
101
|
+
self if count { |i| i.command(command, **) }.positive?
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
# Send a command to every item in the collection, even when {OpenHAB::DSL.ensure_states! ensure_states!} is in effect.
|
|
105
105
|
# @return [self]
|
|
106
|
-
def command!(command, **
|
|
106
|
+
def command!(command, **)
|
|
107
107
|
# We cannot alias this to #command above, otherwise it will call
|
|
108
108
|
# DSL::Items::Ensure::Item#command which checks for ensure_states
|
|
109
|
-
each { |i| i.command!(command, **
|
|
109
|
+
each { |i| i.command!(command, **) }
|
|
110
110
|
self
|
|
111
111
|
end
|
|
112
112
|
|
|
@@ -174,12 +174,6 @@ module OpenHAB
|
|
|
174
174
|
GroupItem.extend(Forwardable)
|
|
175
175
|
GroupItem.def_delegators :members, :equipments, :locations
|
|
176
176
|
|
|
177
|
-
# This is a marker interface for all semantic tag classes.
|
|
178
|
-
# @interface
|
|
179
|
-
# @deprecated Since openHAB 4.0, {SemanticTag} is the interface that all tags implement.
|
|
180
|
-
# Tags are simple instances, instead of another interface in a hierarchical structure.
|
|
181
|
-
Tag = org.openhab.core.semantics.Tag
|
|
182
|
-
|
|
183
177
|
class << self
|
|
184
178
|
# @!visibility private
|
|
185
179
|
def service
|
data/lib/openhab/core/items.rb
CHANGED
|
@@ -42,7 +42,7 @@ module OpenHAB
|
|
|
42
42
|
def def_predicate_methods(klass)
|
|
43
43
|
values_for_enums(klass.ACCEPTED_DATA_TYPES).each do |state|
|
|
44
44
|
_command_predicate, state_predicate = Types::PREDICATE_ALIASES[state.to_s]
|
|
45
|
-
next if klass.
|
|
45
|
+
next if klass.method_defined?(state_predicate)
|
|
46
46
|
|
|
47
47
|
logger.trace { "Defining #{klass}##{state_predicate} for #{state}" }
|
|
48
48
|
klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
@@ -62,7 +62,7 @@ module OpenHAB
|
|
|
62
62
|
def def_command_methods(klass)
|
|
63
63
|
values_for_enums(klass.ACCEPTED_COMMAND_TYPES).each do |value|
|
|
64
64
|
command = Types::COMMAND_ALIASES[value.to_s]
|
|
65
|
-
next if klass.
|
|
65
|
+
next if klass.method_defined?(command)
|
|
66
66
|
|
|
67
67
|
if value.is_a?(Types::State)
|
|
68
68
|
logger.trace { "Defining #{klass}/Enumerable##{command}/#{command}! for #{value}" }
|
|
@@ -128,10 +128,10 @@ module OpenHAB
|
|
|
128
128
|
.select { |k| k <= GenericItem && k != GroupItem && k != StringItem }
|
|
129
129
|
.sort { |a, b| (a < b) ? 1 : -1 }
|
|
130
130
|
.each do |klass|
|
|
131
|
-
|
|
131
|
+
klass.field_reader :ACCEPTED_COMMAND_TYPES, :ACCEPTED_DATA_TYPES unless klass == GenericItem
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
def_predicate_methods(klass)
|
|
134
|
+
def_command_methods(klass)
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
prepend_accepted_data_types
|
|
@@ -36,14 +36,14 @@ module OpenHAB
|
|
|
36
36
|
|
|
37
37
|
# Delegate any other methods to the actual array, exclude mutating methods
|
|
38
38
|
def method_missing(method, ...)
|
|
39
|
-
return to_a.send(method, ...) if method[-1] != "!" && Array.
|
|
39
|
+
return to_a.send(method, ...) if method[-1] != "!" && Array.method_defined?(method)
|
|
40
40
|
|
|
41
41
|
super
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# @!visibility private
|
|
45
45
|
def respond_to_missing?(method, include_private = false)
|
|
46
|
-
return true if method[-1] != "!" && Array.
|
|
46
|
+
return true if method[-1] != "!" && Array.method_defined?(method.to_sym)
|
|
47
47
|
|
|
48
48
|
super
|
|
49
49
|
end
|
|
@@ -48,8 +48,8 @@ module OpenHAB
|
|
|
48
48
|
# @raise [FrozenError] if `update` is true but the existing thing with the same uid
|
|
49
49
|
# wasn't created by the current provider.
|
|
50
50
|
#
|
|
51
|
-
def build(preferred_provider = nil, update: true, &
|
|
52
|
-
DSL::Things::Builder.new(preferred_provider, update:).instance_eval(&
|
|
51
|
+
def build(preferred_provider = nil, update: true, &)
|
|
52
|
+
DSL::Things::Builder.new(preferred_provider, update:).instance_eval(&)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
#
|
|
@@ -18,13 +18,7 @@ module OpenHAB
|
|
|
18
18
|
remove_method :==
|
|
19
19
|
|
|
20
20
|
extend Forwardable
|
|
21
|
-
|
|
22
|
-
# @deprecated OH 4.2 DateTimeType implements Java's Comparable interface in openHAB 4.3
|
|
23
|
-
if OpenHAB::Core.version >= OpenHAB::Core::V4_3
|
|
24
|
-
include ComparableType
|
|
25
|
-
else
|
|
26
|
-
include Comparable
|
|
27
|
-
end
|
|
21
|
+
include ComparableType
|
|
28
22
|
|
|
29
23
|
class << self
|
|
30
24
|
#
|
|
@@ -43,15 +37,8 @@ module OpenHAB
|
|
|
43
37
|
end
|
|
44
38
|
end
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def to_zoned_date_time(context = nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
49
|
-
zoned_date_time(ZoneId.system_default)
|
|
50
|
-
end
|
|
51
|
-
else
|
|
52
|
-
def to_zoned_date_time(context = nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
53
|
-
zoned_date_time
|
|
54
|
-
end
|
|
40
|
+
def to_zoned_date_time(context = nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
41
|
+
zoned_date_time(ZoneId.system_default)
|
|
55
42
|
end
|
|
56
43
|
|
|
57
44
|
# @!method to_zoned_date_time(context = nil)
|
|
@@ -93,7 +80,7 @@ module OpenHAB
|
|
|
93
80
|
if value.nil?
|
|
94
81
|
super()
|
|
95
82
|
return
|
|
96
|
-
elsif
|
|
83
|
+
elsif value.respond_to?(:to_instant)
|
|
97
84
|
super(value.to_instant)
|
|
98
85
|
return
|
|
99
86
|
elsif value.respond_to?(:to_zoned_date_time)
|
|
@@ -122,10 +109,7 @@ module OpenHAB
|
|
|
122
109
|
def eql?(other)
|
|
123
110
|
return false unless other.instance_of?(self.class)
|
|
124
111
|
|
|
125
|
-
|
|
126
|
-
return compare_to(other).zero? if OpenHAB::Core.version >= OpenHAB::Core::V4_3
|
|
127
|
-
|
|
128
|
-
zoned_date_time.compare_to(other.zoned_date_time).zero?
|
|
112
|
+
compare_to(other).zero?
|
|
129
113
|
end
|
|
130
114
|
|
|
131
115
|
#
|
|
@@ -141,10 +125,7 @@ module OpenHAB
|
|
|
141
125
|
def <=>(other)
|
|
142
126
|
logger.trace { "(#{self.class}) #{self} <=> #{other} (#{other.class})" }
|
|
143
127
|
if other.is_a?(self.class)
|
|
144
|
-
|
|
145
|
-
return compare_to(other) if OpenHAB::Core.version >= OpenHAB::Core::V4_3
|
|
146
|
-
|
|
147
|
-
zoned_date_time <=> other.zoned_date_time
|
|
128
|
+
compare_to(other)
|
|
148
129
|
elsif other.respond_to?(:to_time)
|
|
149
130
|
to_time <=> other.to_time
|
|
150
131
|
elsif other.respond_to?(:coerce)
|
|
@@ -222,10 +203,9 @@ module OpenHAB
|
|
|
222
203
|
|
|
223
204
|
# @!visibility private
|
|
224
205
|
def respond_to_missing?(method, _include_private = false)
|
|
225
|
-
|
|
226
|
-
return true if OpenHAB::Core.version >= OpenHAB::Core::V4_3 && to_instant.respond_to?(method)
|
|
206
|
+
return true if to_instant.respond_to?(method)
|
|
227
207
|
return true if zoned_date_time.respond_to?(method)
|
|
228
|
-
return true if ::Time.
|
|
208
|
+
return true if ::Time.method_defined?(method.to_sym)
|
|
229
209
|
|
|
230
210
|
super
|
|
231
211
|
end
|
|
@@ -235,13 +215,9 @@ module OpenHAB
|
|
|
235
215
|
# object representing the same instant
|
|
236
216
|
#
|
|
237
217
|
def method_missing(method, ...)
|
|
238
|
-
|
|
239
|
-
if OpenHAB::Core.version >= OpenHAB::Core::V4_3 && to_instant.respond_to?(method)
|
|
240
|
-
return to_instant.send(method, ...)
|
|
241
|
-
end
|
|
242
|
-
|
|
218
|
+
return to_instant.send(method, ...) if to_instant.respond_to?(method)
|
|
243
219
|
return zoned_date_time.send(method, ...) if zoned_date_time.respond_to?(method)
|
|
244
|
-
return to_time.send(method, ...) if ::Time.
|
|
220
|
+
return to_time.send(method, ...) if ::Time.method_defined?(method.to_sym)
|
|
245
221
|
|
|
246
222
|
super
|
|
247
223
|
end
|
|
@@ -244,8 +244,8 @@ module OpenHAB
|
|
|
244
244
|
# @see planckian?
|
|
245
245
|
# @see https://en.wikipedia.org/wiki/Planckian_locus Planckian Locus
|
|
246
246
|
# @since openHAB 4.3
|
|
247
|
-
def planckian_cct(range: nil, **
|
|
248
|
-
return unless planckian?(**
|
|
247
|
+
def planckian_cct(range: nil, **)
|
|
248
|
+
return unless planckian?(**)
|
|
249
249
|
|
|
250
250
|
range = range.range if range.is_a?(NumberItem)
|
|
251
251
|
cct = self.cct
|
data/lib/openhab/core/types.rb
CHANGED
|
@@ -43,39 +43,39 @@ module OpenHAB
|
|
|
43
43
|
.grep(Module)
|
|
44
44
|
.select { |k| k < java.lang.Enum }
|
|
45
45
|
.each do |klass|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
# make sure == from Type is inherited
|
|
47
|
+
klass.remove_method(:==)
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
# dynamically define predicate methods
|
|
50
|
+
klass.values.each do |value| # rubocop:disable Style/HashEachMethods -- this isn't a Ruby hash
|
|
51
|
+
# include all the aliases that we define for items both command and
|
|
52
|
+
# state aliases (since types can be interrogated as an incoming
|
|
53
|
+
# command, or as the state of an item)
|
|
54
|
+
command = :"#{Types::COMMAND_ALIASES[value.to_s]}?"
|
|
55
|
+
states = Types::PREDICATE_ALIASES[value.to_s]
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
([command] | states).each do |method|
|
|
58
|
+
logger.trace { "Defining #{klass}##{method} for #{value}" }
|
|
59
|
+
klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
60
|
+
def #{method} # def on?
|
|
61
|
+
as(#{value.class.java_class.simple_name}).equal?(#{value}) # as(OnOffType).equal?(ON)
|
|
62
|
+
end # end
|
|
63
|
+
RUBY
|
|
64
|
+
end
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
method = states.last
|
|
67
|
+
Events::ItemState.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
68
|
+
def #{method} # def on?
|
|
69
|
+
item_state.as(#{value.class.java_class.simple_name}).equal?(#{value}) # item_state.as(OnOffType).equal?(ON)
|
|
70
|
+
end # end
|
|
71
|
+
RUBY
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
Events::ItemStateChangedEvent.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
74
|
+
def was_#{method} # def was_on?
|
|
75
|
+
old_item_state.as(#{value.class.java_class.simple_name}).equal?(#{value}) # old_item_state.as(OnOffType).equal?(ON)
|
|
76
|
+
end # end
|
|
77
|
+
RUBY
|
|
78
|
+
end
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
end
|
data/lib/openhab/core.rb
CHANGED
|
@@ -17,6 +17,8 @@ module OpenHAB
|
|
|
17
17
|
V5_0 = Gem::Version.new("5.0.0").freeze
|
|
18
18
|
# @!visibility private
|
|
19
19
|
V5_1 = Gem::Version.new("5.1.0").freeze
|
|
20
|
+
# @!visibility private
|
|
21
|
+
V5_2 = Gem::Version.new("5.2.0").freeze
|
|
20
22
|
|
|
21
23
|
# @return [Gem::Version] Returns the current openHAB version as a Gem::Version object
|
|
22
24
|
# Note, this strips off snapshots, milestones and RC versions and returns the release version.
|
|
@@ -40,7 +42,7 @@ module OpenHAB
|
|
|
40
42
|
@full_version ||= Gem::Version.new(VERSION).freeze
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
raise "`openhab-scripting` requires openHAB >=
|
|
45
|
+
raise "`openhab-scripting` requires openHAB >= 5.0.0" unless version >= V5_0
|
|
44
46
|
|
|
45
47
|
# @return [Integer] Number of seconds to wait between checks for automation manager
|
|
46
48
|
CHECK_DELAY = 10
|
|
@@ -159,6 +161,10 @@ end
|
|
|
159
161
|
require_relative "core/provider"
|
|
160
162
|
|
|
161
163
|
Dir[File.expand_path("core/**/*.rb", __dir__)].each do |f|
|
|
164
|
+
# already been run by either a binstub, or the addon
|
|
165
|
+
next if f.end_with?("gem.rb")
|
|
162
166
|
# metadata is autoloaded
|
|
163
|
-
|
|
167
|
+
next if f.include?("/metadata/")
|
|
168
|
+
|
|
169
|
+
require f
|
|
164
170
|
end
|
|
@@ -36,7 +36,7 @@ module OpenHAB
|
|
|
36
36
|
# @return [true,false] Returns true if the duration is less than zero.
|
|
37
37
|
#
|
|
38
38
|
|
|
39
|
-
unless
|
|
39
|
+
unless method_defined?(:positive?)
|
|
40
40
|
#
|
|
41
41
|
# @return [true, false] Returns true if the duration is greater than zero.
|
|
42
42
|
#
|
|
@@ -354,12 +354,12 @@ module Java::JavaUtil::List # rubocop:disable Style/ClassAndModuleChildren
|
|
|
354
354
|
result
|
|
355
355
|
end
|
|
356
356
|
|
|
357
|
-
def shuffle!(*
|
|
358
|
-
replace(shuffle(*
|
|
357
|
+
def shuffle!(*)
|
|
358
|
+
replace(shuffle(*))
|
|
359
359
|
end
|
|
360
360
|
|
|
361
|
-
def slice(*
|
|
362
|
-
self[*
|
|
361
|
+
def slice(*)
|
|
362
|
+
self[*]
|
|
363
363
|
end
|
|
364
364
|
|
|
365
365
|
def slice!(*args)
|
|
@@ -106,29 +106,33 @@ module OpenHAB
|
|
|
106
106
|
unit_label: nil,
|
|
107
107
|
verify: false)
|
|
108
108
|
# Extract the named arguments into a hash
|
|
109
|
-
@parameters <<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
109
|
+
@parameters <<
|
|
110
|
+
method(__method__)
|
|
111
|
+
.parameters
|
|
112
|
+
.select { |param_type, _| param_type == :key } # rubocop:disable Style/HashSlice
|
|
113
|
+
.to_h { |_, key| [key, binding.local_variable_get(key)] }
|
|
114
|
+
.then do |p|
|
|
115
|
+
p[:options] = p[:options].map do |opt_value, opt_label|
|
|
116
|
+
org.openhab.core.config.core.ParameterOption.new(opt_value, opt_label)
|
|
117
|
+
end
|
|
118
|
+
p[:filter_criteria] = p[:filter_criteria].map do |filter_name, filter_value|
|
|
119
|
+
org.openhab.core.config.core.FilterCriteria.new(filter_name, filter_value)
|
|
120
|
+
end
|
|
121
|
+
p[:minimum] = p.delete(:min)&.to_d&.to_java
|
|
122
|
+
p[:maximum] = p.delete(:max)&.to_d&.to_java
|
|
123
|
+
p[:step] = p.delete(:step)&.to_d&.to_java
|
|
124
|
+
p[:group_name] ||= @current_group
|
|
125
|
+
type = org.openhab.core.config.core.ConfigDescriptionParameter::Type.value_of(type.to_s.upcase)
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
parameter = org.openhab.core.config.core.ConfigDescriptionParameterBuilder.create(
|
|
128
|
+
name.to_s, type
|
|
129
|
+
)
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
p.each do |key, value|
|
|
132
|
+
parameter.send(:"with_#{key}", value) unless value.nil?
|
|
133
|
+
end
|
|
134
|
+
parameter.build
|
|
129
135
|
end
|
|
130
|
-
parameter.build
|
|
131
|
-
end
|
|
132
136
|
end
|
|
133
137
|
|
|
134
138
|
#
|