openhab-scripting 5.15.1 → 5.17.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/entity_lookup.rb +5 -5
- data/lib/openhab/core/events/item_state_updated_event.rb +11 -11
- data/lib/openhab/core/events/item_time_series_updated_event.rb +23 -0
- data/lib/openhab/core/events/timer_event.rb +32 -32
- data/lib/openhab/core/items/generic_item.rb +12 -0
- data/lib/openhab/core/items/numeric_item.rb +1 -1
- data/lib/openhab/core/items/persistence.rb +2 -4
- data/lib/openhab/core/items/registry.rb +1 -3
- data/lib/openhab/core/items/semantics.rb +25 -15
- data/lib/openhab/core/profile_factory.rb +16 -1
- data/lib/openhab/core/sitemaps/provider.rb +3 -1
- data/lib/openhab/core/things/channel.rb +1 -1
- data/lib/openhab/core/things/profile_callback.rb +5 -0
- data/lib/openhab/core/things/thing.rb +7 -1
- data/lib/openhab/core/types/time_series.rb +121 -0
- data/lib/openhab/core.rb +14 -1
- data/lib/openhab/core_ext/java/instant.rb +14 -0
- data/lib/openhab/core_ext/java/list.rb +1 -1
- data/lib/openhab/dsl/config_description/builder.rb +1 -1
- data/lib/openhab/dsl/rules/builder.rb +42 -7
- data/lib/openhab/dsl/rules/name_inference.rb +7 -0
- data/lib/openhab/dsl/rules/property.rb +7 -7
- data/lib/openhab/dsl/rules/terse.rb +32 -15
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +5 -4
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +98 -100
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +1 -1
- data/lib/openhab/dsl/sitemaps/builder.rb +41 -6
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +6 -2
- data/lib/openhab/log.rb +2 -2
- data/lib/openhab/rspec/helpers.rb +7 -4
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +2 -1
- data/lib/openhab/rspec/mocks/thing_handler.rb +4 -0
- data/lib/openhab/yard/coderay.rb +1 -1
- data/lib/openhab/yard.rb +0 -2
- metadata +6 -129
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecc05f177e95b3a962f2b1fac6f924c5af5d6c49ed8a7e38d896c03417fe9e23
|
4
|
+
data.tar.gz: 408fa59899bb838caa9a6f3fc80ef82a4051c03fc590249ab53e0a098c5f335d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccbc0e426427d262cd1f2a5ed671979f5644b4c5b0da5ff34958254de6221283a9420e2b3c45384ac5aafc7feeffd41fa54740f76c4d99ccaa8adba207c32d52
|
7
|
+
data.tar.gz: 9f9a5f3b120a838f151a1f8edf5e1400f1df0a183cef5a47b921bc661889231c1b186ce2830f8cf7349ab3f89b166de5e1ffc89675628dba21799740b9029cc6
|
@@ -74,7 +74,7 @@ module OpenHAB
|
|
74
74
|
ruby2_keywords def method_missing(method, *args)
|
75
75
|
return super unless args.empty? && !block_given?
|
76
76
|
|
77
|
-
logger.trace
|
77
|
+
logger.trace { "method missing, performing openHAB Lookup for: #{method}" }
|
78
78
|
EntityLookup.lookup_entity(method,
|
79
79
|
create_dummy_items: self.class.respond_to?(:create_dummy_items?) &&
|
80
80
|
self.class.create_dummy_items?) || super
|
@@ -82,7 +82,7 @@ module OpenHAB
|
|
82
82
|
|
83
83
|
# @!visibility private
|
84
84
|
def respond_to_missing?(method, *)
|
85
|
-
logger.trace
|
85
|
+
logger.trace { "Checking if openHAB entities exist for #{method}" }
|
86
86
|
EntityLookup.lookup_entity(method) || super
|
87
87
|
end
|
88
88
|
|
@@ -121,14 +121,14 @@ module OpenHAB
|
|
121
121
|
# @return [Things::Thing, nil]
|
122
122
|
#
|
123
123
|
def lookup_thing(uid)
|
124
|
-
logger.trace
|
124
|
+
logger.trace { "Looking up thing '#{uid}'" }
|
125
125
|
uid = uid.to_s if uid.is_a?(Symbol)
|
126
126
|
|
127
127
|
uid = Things::ThingUID.new(uid) unless uid.is_a?(Things::ThingUID)
|
128
128
|
thing = $things.get(uid)
|
129
129
|
return unless thing
|
130
130
|
|
131
|
-
logger.trace
|
131
|
+
logger.trace { "Retrieved Thing(#{thing}) from registry for uid: #{uid}" }
|
132
132
|
Things::Proxy.new(thing)
|
133
133
|
end
|
134
134
|
|
@@ -164,7 +164,7 @@ module OpenHAB
|
|
164
164
|
# @return [Item, nil]
|
165
165
|
#
|
166
166
|
def lookup_item(name)
|
167
|
-
logger.trace
|
167
|
+
logger.trace { "Looking up item '#{name}'" }
|
168
168
|
name = name.to_s if name.is_a?(Symbol)
|
169
169
|
item = $ir.get(name)
|
170
170
|
Items::Proxy.new(item) unless item.nil?
|
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
require_relative "item_state_event"
|
4
4
|
|
5
|
+
# @deprecated OH3.4 guard only needed in OH 3.4
|
6
|
+
return unless OpenHAB::Core.version >= OpenHAB::Core::V4_0
|
7
|
+
|
5
8
|
module OpenHAB
|
6
9
|
module Core
|
7
10
|
module Events
|
8
|
-
|
9
|
-
if Gem::Version.new(OpenHAB::Core::VERSION) >= Gem::Version.new("4.0.0")
|
10
|
-
java_import org.openhab.core.items.events.ItemStateUpdatedEvent
|
11
|
+
java_import org.openhab.core.items.events.ItemStateUpdatedEvent
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
13
|
+
#
|
14
|
+
# {AbstractEvent} sent when an item's state has updated.
|
15
|
+
#
|
16
|
+
# @since openHAB 4.0
|
17
|
+
#
|
18
|
+
class ItemStateUpdatedEvent < ItemEvent
|
19
|
+
include ItemState
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @deprecated OH4.0 guard not needed in OH 4.1
|
4
|
+
return unless OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
5
|
+
|
6
|
+
module OpenHAB
|
7
|
+
module Core
|
8
|
+
module Events
|
9
|
+
java_import org.openhab.core.items.events.ItemTimeSeriesUpdatedEvent
|
10
|
+
|
11
|
+
#
|
12
|
+
# {AbstractEvent} sent when an item received a time series update.
|
13
|
+
#
|
14
|
+
# @!attribute [r] time_series
|
15
|
+
# @return [TimeSeries] The updated time series.
|
16
|
+
#
|
17
|
+
# @since openHAB 4.1
|
18
|
+
# @see DSL::Rules::BuilderDSL#time_series_updated #time_series_updated rule trigger
|
19
|
+
#
|
20
|
+
class ItemTimeSeriesUpdatedEvent < ItemEvent; end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# @deprecated OH3.4 this guard is not needed on OH4
|
4
|
+
return unless OpenHAB::Core.version >= OpenHAB::Core::V4_0
|
5
|
+
|
3
6
|
module OpenHAB
|
4
7
|
module Core
|
5
8
|
module Events
|
6
|
-
|
7
|
-
if Gem::Version.new(OpenHAB::Core::VERSION) >= Gem::Version.new("4.0.0")
|
8
|
-
java_import org.openhab.core.automation.events.TimerEvent
|
9
|
+
java_import org.openhab.core.automation.events.TimerEvent
|
9
10
|
|
11
|
+
#
|
12
|
+
# Adds methods to core openHAB TimerEvent to make it more natural in Ruby
|
13
|
+
#
|
14
|
+
# This event can be triggered by a `DateTimeTrigger`, `cron`, or `TimeOfDay` trigger.
|
15
|
+
#
|
16
|
+
# @since openHAB 4.0
|
17
|
+
#
|
18
|
+
class TimerEvent < AbstractEvent
|
10
19
|
#
|
11
|
-
#
|
20
|
+
# @!attribute [r] cron_expression
|
21
|
+
# @return [String, nil] The cron expression that triggered this event.
|
22
|
+
# `nil` when this event wasn't triggered by a cron trigger.
|
12
23
|
#
|
13
|
-
|
24
|
+
def cron_expression
|
25
|
+
payload&.[](:cronExpression)
|
26
|
+
end
|
27
|
+
|
14
28
|
#
|
15
|
-
#
|
29
|
+
# @!attribute [r] item
|
30
|
+
# @return [Item, nil] The DateTime item that triggered this event.
|
31
|
+
# `nil` when this event wasn't triggered by a DateTimeItem trigger.
|
16
32
|
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# @return [String, nil] The cron expression that triggered this event.
|
21
|
-
# `nil` when this event wasn't triggered by a cron trigger.
|
22
|
-
#
|
23
|
-
def cron_expression
|
24
|
-
payload&.[](:cronExpression)
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# @!attribute [r] item
|
29
|
-
# @return [Item, nil] The DateTime item that triggered this event.
|
30
|
-
# `nil` when this event wasn't triggered by a DateTimeItem trigger.
|
31
|
-
#
|
32
|
-
def item
|
33
|
-
payload&.[](:itemName)&.then { |item_name| EntityLookup.lookup_item(item_name) }
|
34
|
-
end
|
33
|
+
def item
|
34
|
+
payload&.[](:itemName)&.then { |item_name| EntityLookup.lookup_item(item_name) }
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
37
|
+
#
|
38
|
+
# @!attribute [r] time
|
39
|
+
# @return [LocalTime, nil] The configured time for this TimeOfDay trigger event.
|
40
|
+
# `nil` when this event wasn't triggered by a TimeOfDay trigger.
|
41
|
+
#
|
42
|
+
def time
|
43
|
+
payload&.[](:time)&.then { |time| LocalTime.parse(time) }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -207,6 +207,18 @@ module OpenHAB
|
|
207
207
|
type.to_s
|
208
208
|
end
|
209
209
|
|
210
|
+
#
|
211
|
+
# @method time_series=(time_series)
|
212
|
+
# Set a new time series.
|
213
|
+
#
|
214
|
+
# This will trigger a {DSL::Rules::BuilderDSL#time_series_updated time_series_updated} event.
|
215
|
+
#
|
216
|
+
# @param [Core::Types::TimeSeries] time_series New time series to set.
|
217
|
+
# @return [void]
|
218
|
+
#
|
219
|
+
# @since openHAB 4.1
|
220
|
+
#
|
221
|
+
|
210
222
|
#
|
211
223
|
# Defers notifying openHAB of modifications to multiple attributes until the block is complete.
|
212
224
|
#
|
@@ -7,7 +7,7 @@ module OpenHAB
|
|
7
7
|
module Items
|
8
8
|
# Mixin for implementing type coercion for number-like items
|
9
9
|
module NumericItem
|
10
|
-
%i[positive? negative? zero?].each do |predicate|
|
10
|
+
%i[positive? negative? zero? nonzero?].each do |predicate|
|
11
11
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
12
12
|
def #{predicate} # def positive?
|
13
13
|
return false unless state? # return false unless state?
|
@@ -83,9 +83,7 @@ module OpenHAB
|
|
83
83
|
updated_since?])
|
84
84
|
|
85
85
|
# @deprecated OH3.4 - in openHAB 4, just add :get_all_states_since and freeze the list above
|
86
|
-
if
|
87
|
-
PERSISTENCE_METHODS << :get_all_states_since
|
88
|
-
end
|
86
|
+
PERSISTENCE_METHODS << :get_all_states_since if OpenHAB::Core.version >= OpenHAB::Core::V4_0
|
89
87
|
PERSISTENCE_METHODS.freeze
|
90
88
|
|
91
89
|
private_constant :QUANTITY_METHODS, :PERSISTENCE_METHODS
|
@@ -386,7 +384,7 @@ module OpenHAB
|
|
386
384
|
alias_method :state_changes_since, :count_state_changes_since
|
387
385
|
alias_method :state_changes_between, :count_state_changes_between
|
388
386
|
# @deprecated OH 3.4 - if guard is unnecessary in OH4
|
389
|
-
if
|
387
|
+
if OpenHAB::Core.version >= OpenHAB::Core::V4_0
|
390
388
|
alias_method :all_states_since, :get_all_states_since
|
391
389
|
alias_method :all_states_between, :get_all_states_between
|
392
390
|
end
|
@@ -21,15 +21,13 @@ module OpenHAB
|
|
21
21
|
# @return [Item] Item from registry, nil if item missing or requested item is a Group Type
|
22
22
|
def [](name)
|
23
23
|
EntityLookup.lookup_item(name)
|
24
|
-
rescue org.openhab.core.items.ItemNotFoundException
|
25
|
-
nil
|
26
24
|
end
|
27
25
|
|
28
26
|
# Returns true if the given item name exists
|
29
27
|
# @param name [String] Item name to check
|
30
28
|
# @return [true,false] true if the item exists, false otherwise
|
31
29
|
def key?(name)
|
32
|
-
!$ir.
|
30
|
+
!$ir.get(name).nil?
|
33
31
|
end
|
34
32
|
alias_method :include?, :key?
|
35
33
|
# @deprecated
|
@@ -226,10 +226,7 @@ module OpenHAB
|
|
226
226
|
|
227
227
|
# @deprecated OH3.4 - the Property tag had an ID of "MeasurementProperty" in OH3.4.
|
228
228
|
# This was corrected in OH4.
|
229
|
-
|
230
|
-
if id == "Property" && Gem::Version.new(Core::VERSION) < Gem::Version.new("4.0.0.M1")
|
231
|
-
id = "MeasurementProperty"
|
232
|
-
end
|
229
|
+
id = "MeasurementProperty" if id == "Property" && Core.version < Core::V4_0
|
233
230
|
|
234
231
|
# @deprecated OH3.4 missing registry
|
235
232
|
if Provider.registry
|
@@ -607,22 +604,31 @@ module Enumerable
|
|
607
604
|
# @!group Filtering Methods
|
608
605
|
#
|
609
606
|
|
610
|
-
#
|
607
|
+
#
|
608
|
+
# Returns a new array of items that are a semantics Location (optionally of one of the given types)
|
611
609
|
# @return [Array<Item>]
|
612
|
-
|
610
|
+
#
|
611
|
+
# @example Get all rooms
|
612
|
+
# items.locations(Semantics::Room)
|
613
|
+
#
|
614
|
+
# @example Get all bedrooms and bathrooms
|
615
|
+
# items.locations(Semantics::Bedroom, Semantics::Bathroom)
|
616
|
+
#
|
617
|
+
def locations(*types)
|
613
618
|
begin
|
614
|
-
raise ArgumentError
|
619
|
+
raise ArgumentError unless types.all? { |type| type < Semantics::Location }
|
615
620
|
rescue ArgumentError, TypeError
|
616
621
|
raise ArgumentError, "type must be a subclass of Location"
|
617
622
|
end
|
618
623
|
|
619
624
|
result = select(&:location?)
|
620
|
-
result.select! { |i| i.location_type <= type }
|
625
|
+
result.select! { |i| types.any? { |type| i.location_type <= type } } unless types.empty?
|
621
626
|
|
622
627
|
result
|
623
628
|
end
|
624
629
|
|
625
|
-
#
|
630
|
+
#
|
631
|
+
# Returns a new array of items that are a semantics equipment (optionally of one of the given types)
|
626
632
|
#
|
627
633
|
# @note As {Semantics::Equipment equipments} are usually
|
628
634
|
# {GroupItem GroupItems}, this method therefore returns an array of
|
@@ -633,16 +639,20 @@ module Enumerable
|
|
633
639
|
# @return [Array<Item>]
|
634
640
|
#
|
635
641
|
# @example Get all TVs in a room
|
636
|
-
# lGreatRoom.equipments(Semantics::
|
637
|
-
|
642
|
+
# lGreatRoom.equipments(Semantics::Television)
|
643
|
+
#
|
644
|
+
# @example Get all TVs and Speakers in a room
|
645
|
+
# lGreatRoom.equipments(Semantics::Television, Semantics::Speaker)
|
646
|
+
#
|
647
|
+
def equipments(*types)
|
638
648
|
begin
|
639
|
-
raise ArgumentError
|
649
|
+
raise ArgumentError unless types.all? { |type| type < Semantics::Equipment }
|
640
650
|
rescue ArgumentError, TypeError
|
641
651
|
raise ArgumentError, "type must be a subclass of Equipment"
|
642
652
|
end
|
643
653
|
|
644
654
|
result = select(&:equipment?)
|
645
|
-
result.select! { |i| i.equipment_type <= type }
|
655
|
+
result.select! { |i| types.any? { |type| i.equipment_type <= type } } unless types.empty?
|
646
656
|
|
647
657
|
result
|
648
658
|
end
|
@@ -663,8 +673,8 @@ module Enumerable
|
|
663
673
|
|
664
674
|
begin
|
665
675
|
raise ArgumentError unless point_or_property_types.all? do |tag|
|
666
|
-
|
667
|
-
|
676
|
+
tag < Semantics::Point ||
|
677
|
+
tag < Semantics::Property
|
668
678
|
end
|
669
679
|
rescue ArgumentError, TypeError
|
670
680
|
raise ArgumentError, "point_or_property_types must all be a subclass of Point or Property"
|
@@ -15,7 +15,12 @@ module OpenHAB
|
|
15
15
|
include Singleton
|
16
16
|
|
17
17
|
class Profile
|
18
|
-
include
|
18
|
+
# @deprecated OH 4.0 only include TimeSeriesProfile in OH 4.1, because it extends StateProfile
|
19
|
+
if OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
20
|
+
include org.openhab.core.thing.profiles.TimeSeriesProfile
|
21
|
+
else
|
22
|
+
include org.openhab.core.thing.profiles.StateProfile
|
23
|
+
end
|
19
24
|
|
20
25
|
def initialize(callback, context, uid, thread_locals, block)
|
21
26
|
unless callback.class.ancestors.include?(Things::ProfileCallback)
|
@@ -64,6 +69,14 @@ module OpenHAB
|
|
64
69
|
process_event(:state_from_item, state: state)
|
65
70
|
end
|
66
71
|
|
72
|
+
# @deprecated OH 4.0 guard is only needed for < OH 4.1
|
73
|
+
if OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
74
|
+
# @!visibility private
|
75
|
+
def onTimeSeriesFromHandler(time_series)
|
76
|
+
process_event(:time_series_from_handler, time_series: time_series)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
67
80
|
private
|
68
81
|
|
69
82
|
def process_event(event, **params)
|
@@ -77,6 +90,8 @@ module OpenHAB
|
|
77
90
|
params[:channel_uid] = @callback.link.linked_uid
|
78
91
|
params[:state] ||= nil
|
79
92
|
params[:command] ||= nil
|
93
|
+
# @deprecated OH 4.0 guard is only needed for < OH 4.1
|
94
|
+
params[:time_series] ||= nil if OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
80
95
|
|
81
96
|
kwargs = {}
|
82
97
|
@block.parameters.each do |(param_type, name)|
|
@@ -132,7 +132,9 @@ module OpenHAB
|
|
132
132
|
builder = DSL::Sitemaps::Builder.new(self, builder_proxy, update: update)
|
133
133
|
if block.arity == 1
|
134
134
|
builder_proxy.__setobj__(builder)
|
135
|
-
|
135
|
+
DSL::ThreadLocal.thread_local(openhab_create_dummy_items: true) do
|
136
|
+
yield builder_proxy
|
137
|
+
end
|
136
138
|
else
|
137
139
|
builder.instance_eval(&block)
|
138
140
|
end
|
@@ -58,7 +58,7 @@ module OpenHAB
|
|
58
58
|
end
|
59
59
|
|
60
60
|
# @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
|
61
|
-
if
|
61
|
+
if Core.version < Core::V4_0
|
62
62
|
# @!visibility private
|
63
63
|
module ChannelComparable
|
64
64
|
# @!visibility private
|
@@ -137,7 +137,7 @@ module OpenHAB
|
|
137
137
|
#
|
138
138
|
|
139
139
|
ThingStatus.constants.each do |thingstatus|
|
140
|
-
define_method("#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
|
140
|
+
define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
|
141
141
|
end
|
142
142
|
|
143
143
|
#
|
@@ -165,6 +165,12 @@ module OpenHAB
|
|
165
165
|
ThingType.registry.get_thing_type(thing_type_uid)
|
166
166
|
end
|
167
167
|
|
168
|
+
# @!attribute [r] bridge
|
169
|
+
# @return [Thing, nil]
|
170
|
+
def bridge
|
171
|
+
bridge_uid && EntityLookup.lookup_thing(bridge_uid)
|
172
|
+
end
|
173
|
+
|
168
174
|
# @return [String]
|
169
175
|
def inspect
|
170
176
|
r = "#<OpenHAB::Core::Things::Thing #{uid}"
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @deprecated OH4.0 this guard is not needed on OH4.1
|
4
|
+
return unless OpenHAB::Core.version >= OpenHAB::Core::V4_1
|
5
|
+
|
6
|
+
require "forwardable"
|
7
|
+
|
8
|
+
module OpenHAB
|
9
|
+
module Core
|
10
|
+
module Types
|
11
|
+
TimeSeries = org.openhab.core.types.TimeSeries
|
12
|
+
|
13
|
+
#
|
14
|
+
# {TimeSeries} is used to transport a set of states together with their timestamp.
|
15
|
+
#
|
16
|
+
# The states are sorted chronologically. The entries can be accessed like an array.
|
17
|
+
#
|
18
|
+
# @since openHAB 4.1
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# time_series = TimeSeries.new # defaults to :add policy
|
22
|
+
# .add(Time.at(2), DecimalType.new(2))
|
23
|
+
# .add(Time.at(1), DecimalType.new(1))
|
24
|
+
# .add(Time.at(3), DecimalType.new(3))
|
25
|
+
# logger.info "first entry: #{time_series.first.state}" # => 1
|
26
|
+
# logger.info "last entry: #{time_series.last.state}" # => 3
|
27
|
+
# logger.info "second entry: #{time_series[1].state}" # => 2
|
28
|
+
# logger.info "sum: #{time_series.sum(&:state)}" # => 6
|
29
|
+
#
|
30
|
+
# @see DSL::Rules::BuilderDSL#time_series_updated #time_series_updated rule trigger
|
31
|
+
#
|
32
|
+
class TimeSeries
|
33
|
+
extend Forwardable
|
34
|
+
|
35
|
+
# @!attribute [r] policy
|
36
|
+
# Returns the persistence policy of this series.
|
37
|
+
# @see org.openhab.core.types.TimeSeries#getPolicy()
|
38
|
+
# @return [org.openhab.core.types.TimeSeries.Policy]
|
39
|
+
|
40
|
+
# @!attribute [r] begin
|
41
|
+
# Returns the timestamp of the first element in this series.
|
42
|
+
# @return [Instant]
|
43
|
+
|
44
|
+
# @!attribute [r] end
|
45
|
+
# Returns the timestamp of the last element in this series.
|
46
|
+
# @return [Instant]
|
47
|
+
|
48
|
+
# @!attribute [r] size
|
49
|
+
# Returns the number of elements in this series.
|
50
|
+
# @return [Integer]
|
51
|
+
|
52
|
+
#
|
53
|
+
# Create a new instance of TimeSeries
|
54
|
+
#
|
55
|
+
# @param [:add, :replace, org.openhab.core.types.TimeSeries.Policy] policy
|
56
|
+
# The persistence policy of this series.
|
57
|
+
#
|
58
|
+
def initialize(policy = :replace)
|
59
|
+
policy = Policy.value_of(policy.to_s.upcase) if policy.is_a?(Symbol)
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns true if the series' policy is `ADD`.
|
64
|
+
# @return [true,false]
|
65
|
+
def add?
|
66
|
+
policy == Policy::ADD
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns true if the series' policy is `REPLACE`.
|
70
|
+
# @return [true,false]
|
71
|
+
def replace?
|
72
|
+
policy == Policy::REPLACE
|
73
|
+
end
|
74
|
+
|
75
|
+
# @!visibility private
|
76
|
+
def inspect
|
77
|
+
"#<OpenHAB::Core::Types::TimeSeries " \
|
78
|
+
"policy=#{policy} " \
|
79
|
+
"begin=#{self.begin} " \
|
80
|
+
"end=#{self.end} " \
|
81
|
+
"size=#{size}>"
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Returns the content of this series.
|
86
|
+
# @return [Array<org.openhab.core.types.TimeSeries.Entry>]
|
87
|
+
#
|
88
|
+
def states
|
89
|
+
get_states.to_array.to_a.freeze
|
90
|
+
end
|
91
|
+
|
92
|
+
# rename raw methods so we can overwrite them
|
93
|
+
# @!visibility private
|
94
|
+
alias_method :add_instant, :add
|
95
|
+
|
96
|
+
#
|
97
|
+
# Adds a new element to this series.
|
98
|
+
#
|
99
|
+
# Elements can be added in an arbitrary order and are sorted chronologically.
|
100
|
+
#
|
101
|
+
# @note This method returns self so it can be chained, unlike the Java version.
|
102
|
+
#
|
103
|
+
# @param [Instant, #to_zoned_date_time, #to_instant] instant An instant for the given state.
|
104
|
+
# @param [State] state The State at the given timestamp.
|
105
|
+
# @return [self]
|
106
|
+
#
|
107
|
+
def add(instant, state)
|
108
|
+
instant = instant.to_zoned_date_time if instant.respond_to?(:to_zoned_date_time)
|
109
|
+
instant = instant.to_instant if instant.respond_to?(:to_instant)
|
110
|
+
add_instant(instant, state)
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
# any method that exists on Array gets forwarded to states
|
115
|
+
delegate (Array.instance_methods - instance_methods) => :states
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
TimeSeries = OpenHAB::Core::Types::TimeSeries unless Object.const_defined?(:TimeSeries)
|
data/lib/openhab/core.rb
CHANGED
@@ -7,7 +7,20 @@ module OpenHAB
|
|
7
7
|
# @return [String]
|
8
8
|
VERSION = org.openhab.core.OpenHAB.version.freeze
|
9
9
|
|
10
|
-
|
10
|
+
# @!visibility private
|
11
|
+
V4_0 = Gem::Version.new("4.0.0").freeze
|
12
|
+
# @!visibility private
|
13
|
+
V4_1 = Gem::Version.new("4.1.0").freeze
|
14
|
+
# @!visibility private
|
15
|
+
V4_2 = Gem::Version.new("4.2.0").freeze
|
16
|
+
|
17
|
+
# @return [Gem::Version] Returns the current openHAB version as a Gem::Version object
|
18
|
+
# @!visibility private
|
19
|
+
def self.version
|
20
|
+
@version ||= Gem::Version.new(VERSION).freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
raise "`openhab-scripting` requires openHAB >= 3.4.0" unless version >= Gem::Version.new("3.4.0")
|
11
24
|
|
12
25
|
# @return [Integer] Number of seconds to wait between checks for automation manager
|
13
26
|
CHECK_DELAY = 10
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module CoreExt
|
5
|
+
module Java
|
6
|
+
java_import java.time.Instant
|
7
|
+
|
8
|
+
# Extensions to {java.time.Instant}
|
9
|
+
class Instant < java.lang.Object; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Instant = OpenHAB::CoreExt::Java::Instant unless Object.const_defined?(:Instant)
|
@@ -125,7 +125,7 @@ module OpenHAB
|
|
125
125
|
parameter = org.openhab.core.config.core.ConfigDescriptionParameterBuilder.create(name.to_s, type)
|
126
126
|
|
127
127
|
p.each do |key, value|
|
128
|
-
parameter.send("with_#{key}", value) unless value.nil?
|
128
|
+
parameter.send(:"with_#{key}", value) unless value.nil?
|
129
129
|
end
|
130
130
|
parameter.build
|
131
131
|
end
|