openhab-scripting 4.17.0 → 4.20.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/dsl/dsl.rb +1 -0
- data/lib/openhab/dsl/items/switch_item.rb +8 -0
- data/lib/openhab/dsl/rules/rule.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +14 -12
- data/lib/openhab/dsl/things.rb +1 -1
- data/lib/openhab/dsl/timers/timer.rb +25 -6
- data/lib/openhab/dsl/types/type.rb +14 -0
- data/lib/openhab/dsl/uid.rb +55 -0
- data/lib/openhab/version.rb +1 -1
- data/lib/openhab.rb +0 -5
- 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: 48c997bfb2b0275d7c7666b905eb1599e020c9d434965d9093613540b77460b1
|
4
|
+
data.tar.gz: a81a610e16bb811762faf1e7317432a86e7c332d7356b1b2bea827d674f1442c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae48e5f3f7e607c81fd2343a094b88e1b6c2041dc398357401ede48a41f0259f60d7c100afc4e3bd3d5217f635cf0d31e77cf072fbbe2b3871bf4f2d85477d94
|
7
|
+
data.tar.gz: 2ad2e05fa15ebc3a6de85ed5de804935d7d48d3b3e6a442dce0846fb0ccf993d07c04d09bed6861d4eb0d1b247a4d20a2d045156f150c9e76105fa7f9a75c361
|
data/lib/openhab/dsl/dsl.rb
CHANGED
@@ -20,6 +20,14 @@ module OpenHAB
|
|
20
20
|
on?
|
21
21
|
end
|
22
22
|
|
23
|
+
# Convert boolean commands to ON/OFF
|
24
|
+
# @!visibility private
|
25
|
+
def format_type(command)
|
26
|
+
return Types::OnOffType.from(command) if [true, false].include?(command)
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
23
31
|
#
|
24
32
|
# Send a command to invert the state of the switch
|
25
33
|
#
|
@@ -38,6 +38,7 @@ module OpenHAB
|
|
38
38
|
config.guard = Guard::Guard.new(only_if: config.only_if, not_if: config.not_if)
|
39
39
|
logger.trace { config.inspect }
|
40
40
|
process_rule_config(config)
|
41
|
+
nil # Must return something other than the rule object. See https://github.com/boc-tothefuture/openhab-jruby/issues/438
|
41
42
|
rescue StandardError => e
|
42
43
|
re_raise_with_backtrace(e)
|
43
44
|
end
|
@@ -15,16 +15,19 @@ module OpenHAB
|
|
15
15
|
#
|
16
16
|
# Creates a channel trigger
|
17
17
|
#
|
18
|
-
# @param [
|
18
|
+
# @param [String, Channel, ChannelUID, Array<String, Channel, ChannelUID>] channels
|
19
|
+
# channels to create triggers for in form of 'binding_id:type_id:thing_id#channel_id'
|
19
20
|
# or 'channel_id' if thing is provided
|
20
|
-
# @param [
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
def channel(*channels, thing: nil, triggered: nil, attach: nil)
|
25
|
-
channels.flatten.each do |channel|
|
26
|
-
channel =
|
27
|
-
|
21
|
+
# @param [String, Thing, ThingUID, Array<String, Thing, ThingUID>] thing
|
22
|
+
# thing(s) to create trigger for if not specified with the channel
|
23
|
+
# @param [String, Array<String>] triggered specific triggering condition(s) to match for trigger
|
24
|
+
#
|
25
|
+
def channel(*channels, thing: nil, triggered: nil, attach: nil) # rubocop:disable Metrics/AbcSize
|
26
|
+
channels.flatten.product([thing].flatten).each do |(channel, t)|
|
27
|
+
channel = channel.uid if channel.is_a?(org.openhab.core.thing.Channel)
|
28
|
+
t = t.uid if t.is_a?(Thing)
|
29
|
+
channel = [t, channel].compact.join(':')
|
30
|
+
logger.trace("Creating channel trigger for channel(#{channel}), thing(#{t}), trigger(#{triggered})")
|
28
31
|
[triggered].flatten.each do |trigger|
|
29
32
|
create_channel_trigger(channel, trigger, attach)
|
30
33
|
end
|
@@ -36,14 +39,13 @@ module OpenHAB
|
|
36
39
|
#
|
37
40
|
# Create a trigger for a channel
|
38
41
|
#
|
39
|
-
# @param [
|
40
|
-
# @param [
|
42
|
+
# @param [String] channel to look for triggers
|
43
|
+
# @param [String] trigger specific channel trigger to match
|
41
44
|
#
|
42
45
|
#
|
43
46
|
def create_channel_trigger(channel, trigger, attach)
|
44
47
|
config = { 'channelUID' => channel }
|
45
48
|
config['event'] = trigger.to_s unless trigger.nil?
|
46
|
-
config['channelUID'] = channel
|
47
49
|
logger.trace("Creating Change Trigger for #{config}")
|
48
50
|
append_trigger(Trigger::CHANNEL_EVENT, config, attach: attach)
|
49
51
|
end
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -41,7 +41,7 @@ module OpenHAB
|
|
41
41
|
|
42
42
|
semaphore.synchronize do
|
43
43
|
@timer = ScriptExecution.createTimer(
|
44
|
-
ZonedDateTime.now.plus(@duration), timer_block(semaphore, &block)
|
44
|
+
ZonedDateTime.now.plus(to_duration(@duration)), timer_block(semaphore, &block)
|
45
45
|
)
|
46
46
|
@rule_timers = Thread.current[:rule_timers]
|
47
47
|
super(@timer)
|
@@ -57,15 +57,13 @@ module OpenHAB
|
|
57
57
|
# @return [Timer] Rescheduled timer instances
|
58
58
|
#
|
59
59
|
def reschedule(duration = nil)
|
60
|
-
unless duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
|
61
|
-
raise ArgumentError, 'Supplied argument must be a duration'
|
62
|
-
end
|
63
|
-
|
64
60
|
duration ||= @duration
|
61
|
+
|
65
62
|
Timers.timer_manager.add(self)
|
66
|
-
@timer.reschedule(ZonedDateTime.now.plus(duration))
|
63
|
+
@timer.reschedule(ZonedDateTime.now.plus(to_duration(duration)))
|
67
64
|
end
|
68
65
|
|
66
|
+
#
|
69
67
|
# Cancel timer
|
70
68
|
#
|
71
69
|
# @return [Boolean] True if cancel was successful, false otherwise
|
@@ -92,6 +90,27 @@ module OpenHAB
|
|
92
90
|
end
|
93
91
|
}
|
94
92
|
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Convert argument to a duration
|
96
|
+
#
|
97
|
+
# @params [Java::JavaTimeTemporal::TemporalAmount, #to_f, #to_i, nil] duration Duration
|
98
|
+
#
|
99
|
+
# @raise if duration cannot be used for a timer
|
100
|
+
#
|
101
|
+
# @return Argument converted to seconds if it responds to #to_f or #to_i, otherwise duration unchanged
|
102
|
+
#
|
103
|
+
def to_duration(duration)
|
104
|
+
if duration.nil? || duration.is_a?(Java::JavaTimeTemporal::TemporalAmount)
|
105
|
+
duration
|
106
|
+
elsif duration.respond_to?(:to_f)
|
107
|
+
duration.to_f.seconds
|
108
|
+
elsif duration.respond_to?(:to_i)
|
109
|
+
duration.to_i.seconds
|
110
|
+
else
|
111
|
+
raise ArgumentError, "Supplied argument '#{duration}' cannot be converted to a duration"
|
112
|
+
end
|
113
|
+
end
|
95
114
|
end
|
96
115
|
end
|
97
116
|
end
|
@@ -41,6 +41,20 @@ module OpenHAB
|
|
41
41
|
equals(other)
|
42
42
|
end
|
43
43
|
|
44
|
+
#
|
45
|
+
# Case equality
|
46
|
+
#
|
47
|
+
# @return [Boolean] if the values are of the same Type
|
48
|
+
# or item state of the same type
|
49
|
+
#
|
50
|
+
def ===(other)
|
51
|
+
logger.trace("(#{self.class}) #{self} === #{other} (#{other.class})")
|
52
|
+
other = other.state if other.respond_to?(:state)
|
53
|
+
return false unless instance_of?(other.class)
|
54
|
+
|
55
|
+
eql?(other)
|
56
|
+
end
|
57
|
+
|
44
58
|
#
|
45
59
|
# Check equality, including type conversion
|
46
60
|
#
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module DSL
|
5
|
+
java_import org.openhab.core.common.AbstractUID
|
6
|
+
java_import org.openhab.core.thing.ThingTypeUID
|
7
|
+
|
8
|
+
# Adds methods to core OpenHAB AbstractUID to make it more natural in Ruby
|
9
|
+
class AbstractUID
|
10
|
+
# implicit conversion to string
|
11
|
+
alias to_str to_s
|
12
|
+
# inspect result is just the string representation
|
13
|
+
alias inspect to_s
|
14
|
+
|
15
|
+
# compares if equal to `other`, including string conversion
|
16
|
+
# @return [true, false]
|
17
|
+
def ==(other)
|
18
|
+
return true if equals(other)
|
19
|
+
|
20
|
+
to_s == other
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Adds methods to core OpenHAB ThingUID to make it more natural in Ruby
|
25
|
+
class ThingUID
|
26
|
+
# Returns the id of the binding this thing belongs to
|
27
|
+
# @return [String]
|
28
|
+
def binding_id
|
29
|
+
get_segment(0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Adds methods to core OpenHAB ThingTypeUID to make it more natural in Ruby
|
34
|
+
class ThingTypeUID
|
35
|
+
# Returns the id of the binding this thing type belongs to
|
36
|
+
# @return [String]
|
37
|
+
def binding_id
|
38
|
+
get_segment(0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# have to remove == from all descendant classes so that they'll inherit
|
43
|
+
# the new implementation
|
44
|
+
[org.openhab.core.items.MetadataKey,
|
45
|
+
org.openhab.core.thing.UID,
|
46
|
+
org.openhab.core.thing.ChannelUID,
|
47
|
+
org.openhab.core.thing.ChannelGroupUID,
|
48
|
+
org.openhab.core.thing.ThingUID,
|
49
|
+
org.openhab.core.thing.ThingTypeUID,
|
50
|
+
org.openhab.core.thing.type.ChannelTypeUID,
|
51
|
+
org.openhab.core.thing.type.ChannelGroupTypeUID].each do |klass|
|
52
|
+
klass.remove_method(:==)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/openhab/version.rb
CHANGED
data/lib/openhab.rb
CHANGED
@@ -20,23 +20,18 @@ module OpenHAB
|
|
20
20
|
#
|
21
21
|
#
|
22
22
|
# Number of extensions and includes requires more lines
|
23
|
-
# rubocop: disable Metrics/MethodLength
|
24
23
|
def self.extended(base)
|
25
24
|
OpenHAB::Core.wait_till_openhab_ready
|
26
25
|
base.extend Log
|
27
26
|
base.extend OpenHAB::Core::ScriptHandling
|
28
27
|
base.extend OpenHAB::Core::EntityLookup
|
29
28
|
base.extend OpenHAB::DSL
|
30
|
-
base.extend OpenHAB::DSL::Between
|
31
29
|
|
32
30
|
base.send :include, OpenHAB::Core::ScriptHandlingCallbacks
|
33
|
-
base.send :include, OpenHAB::DSL::Items
|
34
|
-
base.send :include, OpenHAB::DSL::Types
|
35
31
|
logger.info "OpenHAB JRuby Scripting Library Version #{OpenHAB::VERSION} Loaded"
|
36
32
|
|
37
33
|
OpenHAB::Core.add_rubylib_to_load_path
|
38
34
|
end
|
39
|
-
# rubocop: enable Metrics/MethodLength
|
40
35
|
end
|
41
36
|
|
42
37
|
# Extend caller with OpenHAB methods
|
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.20.0
|
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-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/openhab/dsl/types/types.rb
|
137
137
|
- lib/openhab/dsl/types/un_def_type.rb
|
138
138
|
- lib/openhab/dsl/types/up_down_type.rb
|
139
|
+
- lib/openhab/dsl/uid.rb
|
139
140
|
- lib/openhab/dsl/units.rb
|
140
141
|
- lib/openhab/log/configuration.rb
|
141
142
|
- lib/openhab/log/logger.rb
|