openhab-scripting 4.29.0 → 4.30.3
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/items/group_item.rb +7 -0
- data/lib/openhab/dsl/items/item_registry.rb +1 -1
- data/lib/openhab/dsl/items/persistence.rb +1 -2
- data/lib/openhab/dsl/rules/rule_config.rb +2 -2
- data/lib/openhab/dsl/rules/triggers/changed.rb +28 -9
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +13 -39
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +150 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +19 -7
- data/lib/openhab/dsl/types/date_time_type.rb +2 -2
- data/lib/openhab/dsl/types/hsb_type.rb +2 -2
- data/lib/openhab/dsl/types/percent_type.rb +2 -2
- data/lib/openhab/dsl/types/point_type.rb +2 -2
- data/lib/openhab/dsl/types/quantity_type.rb +10 -10
- data/lib/openhab/log/logger.rb +1 -2
- data/lib/openhab/version.rb +1 -1
- metadata +3 -4
- data/lib/openhab/dsl/rules/triggers/conditions/none.rb +0 -32
- data/lib/openhab/dsl/rules/triggers/conditions/range.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5916a1adf8f4162530b88e279d0d8a8cb5cdb7f0505572258e1170ed7841460f
|
4
|
+
data.tar.gz: d3e9073dbde176abf8582e51eb6009a953befde6fd05b9a782fa3c3a09400ed3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39b84e0831b3ec13c643cc65eea2a45f2d9971fbf8ac9dc0bb53a44ab7ad767b2ab75f88dfe0db96dd274c30f40eab4f9ab876603d2e9c001f107ecec2a6d15
|
7
|
+
data.tar.gz: c9712062f693f5a4fd903ce8fbd06a441622850b94c240b6e5ade99a7a0754c1576ef78e69e518ec537728a7233ea8794090ace0016873628dccf5595067fb4e
|
@@ -99,8 +99,7 @@ module OpenHAB
|
|
99
99
|
# @return [Object] QuantityType or the original value
|
100
100
|
#
|
101
101
|
def quantify(value)
|
102
|
-
if value.is_a?(Types::DecimalType) && state_description&.pattern
|
103
|
-
item_unit = UnitUtils.parse_unit(state_description.pattern)
|
102
|
+
if value.is_a?(Types::DecimalType) && (item_unit = UnitUtils.parse_unit(state_description&.pattern))
|
104
103
|
logger.trace("Unitizing #{value} with unit #{item_unit}")
|
105
104
|
Types::QuantityType.new(value.to_big_decimal, item_unit)
|
106
105
|
else
|
@@ -10,7 +10,7 @@ require_relative 'triggers/command'
|
|
10
10
|
require_relative 'triggers/updated'
|
11
11
|
require_relative 'triggers/generic'
|
12
12
|
require_relative 'triggers/watch'
|
13
|
-
require_relative 'triggers/conditions/
|
13
|
+
require_relative 'triggers/conditions/proc'
|
14
14
|
require_relative 'guard'
|
15
15
|
require 'openhab/core/entity_lookup'
|
16
16
|
require 'openhab/dsl/between'
|
@@ -87,7 +87,7 @@ module OpenHAB
|
|
87
87
|
#
|
88
88
|
def initialize(rule_name, caller_binding)
|
89
89
|
@triggers = []
|
90
|
-
@trigger_conditions = Hash.new(OpenHAB::DSL::Rules::Triggers::Conditions::
|
90
|
+
@trigger_conditions = Hash.new(OpenHAB::DSL::Rules::Triggers::Conditions::Proc::ANY)
|
91
91
|
@attachments = {}
|
92
92
|
@caller = caller_binding.eval 'self'
|
93
93
|
name(rule_name)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'openhab/log/logger'
|
4
4
|
require_relative 'conditions/duration'
|
5
|
-
require_relative 'conditions/
|
5
|
+
require_relative 'conditions/proc'
|
6
6
|
|
7
7
|
module OpenHAB
|
8
8
|
module DSL
|
@@ -74,6 +74,8 @@ module OpenHAB
|
|
74
74
|
changed_wait(item, from: from, to: to, duration: duration, attach: attach)
|
75
75
|
elsif [to, from].grep(Range).any?
|
76
76
|
create_changed_range_trigger(item, from: from, to: to, attach: attach)
|
77
|
+
elsif [to, from].grep(Proc).any?
|
78
|
+
create_changed_proc_trigger(item, from: from, to: to, attach: attach)
|
77
79
|
else
|
78
80
|
create_changed_trigger(item, from, to, attach)
|
79
81
|
end
|
@@ -91,10 +93,12 @@ module OpenHAB
|
|
91
93
|
# @return [Trigger] OpenHAB trigger
|
92
94
|
#
|
93
95
|
def changed_wait(item, duration:, to: nil, from: nil, attach: nil)
|
94
|
-
|
95
|
-
logger.trace("Creating Changed Wait Change Trigger for #{
|
96
|
-
|
97
|
-
trigger
|
96
|
+
item_name = item.respond_to?(:name) ? item.name : item.to_s
|
97
|
+
logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) "\
|
98
|
+
"To(#{to}) From(#{from}) Attach(#{attach})")
|
99
|
+
create_changed_trigger(item, nil, nil, attach).tap do |trigger|
|
100
|
+
@trigger_conditions[trigger.id] = Conditions::Duration.new(to: to, from: from, duration: duration)
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
104
|
#
|
@@ -106,11 +110,26 @@ module OpenHAB
|
|
106
110
|
# @return [Trigger] OpenHAB trigger
|
107
111
|
#
|
108
112
|
def create_changed_range_trigger(item, from:, to:, attach:)
|
109
|
-
|
110
|
-
|
111
|
-
|
113
|
+
from, to = Conditions::Proc.range_procs(from, to)
|
114
|
+
create_changed_proc_trigger(item, from: from, to: to, attach: attach)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Creates a trigger with a proc condition on either 'from' or 'to' field
|
119
|
+
# @param [Object] item to create changed trigger on
|
120
|
+
# @param [Object] from state to restrict trigger to
|
121
|
+
# @param [Object] to state restrict trigger to
|
122
|
+
# @param [Object] attach to trigger
|
123
|
+
# @return [Trigger] OpenHAB trigger
|
124
|
+
#
|
125
|
+
def create_changed_proc_trigger(item, from:, to:, attach:)
|
126
|
+
# swap from/to w/ nil if from/to is a proc
|
127
|
+
# rubocop:disable Style/ParallelAssignment
|
128
|
+
from_proc, from = from, nil if from.is_a? Proc
|
129
|
+
to_proc, to = to, nil if to.is_a? Proc
|
130
|
+
# rubocop:enable Style/ParallelAssignment
|
112
131
|
trigger = create_changed_trigger(item, from, to, attach)
|
113
|
-
@trigger_conditions[trigger.id] = Conditions::
|
132
|
+
@trigger_conditions[trigger.id] = Conditions::Proc.new(to: to_proc, from: from_proc)
|
114
133
|
trigger
|
115
134
|
end
|
116
135
|
|
@@ -23,12 +23,20 @@ module OpenHAB
|
|
23
23
|
# timer&.is_active
|
24
24
|
# end
|
25
25
|
# end
|
26
|
-
|
27
26
|
class Duration
|
27
|
+
#
|
28
|
+
# Create a new duration condition
|
29
|
+
# @param [Object] to optional condition on to state
|
30
|
+
# @param [Object] from optional condition on from state
|
31
|
+
# @param [Duration] Duration to state must stay at specific value before triggering
|
32
|
+
#
|
28
33
|
def initialize(to:, from:, duration:)
|
29
|
-
|
30
|
-
|
34
|
+
to = Conditions::Proc.from_value(to)
|
35
|
+
from = Conditions::Proc.from_value(from)
|
36
|
+
@conditions = Conditions::Proc.new(to: to, from: from)
|
31
37
|
@duration = duration
|
38
|
+
logger.trace "Created Duration Condition To(#{to}) From(#{from}) "\
|
39
|
+
"Conditions(#{@conditions}) Duration(#{@duration})"
|
32
40
|
end
|
33
41
|
|
34
42
|
# Process rule
|
@@ -56,15 +64,7 @@ module OpenHAB
|
|
56
64
|
#
|
57
65
|
def check_trigger_guards(inputs)
|
58
66
|
new_state, old_state = retrieve_states(inputs)
|
59
|
-
|
60
|
-
return true if check_to(new_state)
|
61
|
-
|
62
|
-
logger.trace("Skipped execution of rule because to state #{new_state}"\
|
63
|
-
" does not equal specified state(#{@to})")
|
64
|
-
else
|
65
|
-
logger.trace("Skipped execution of rule because old state #{old_state}"\
|
66
|
-
" does not equal specified state(#{@from})")
|
67
|
-
end
|
67
|
+
@conditions.check_from(state: old_state) && @conditions.check_to(state: new_state)
|
68
68
|
end
|
69
69
|
|
70
70
|
#
|
@@ -76,8 +76,8 @@ module OpenHAB
|
|
76
76
|
# @return [Array] An array of the values for [newState, oldState] or [newStatus, oldStatus]
|
77
77
|
#
|
78
78
|
def retrieve_states(inputs)
|
79
|
-
old_state = inputs['oldState'] || thing_status_to_sym(inputs['oldStatus'])
|
80
79
|
new_state = inputs['newState'] || thing_status_to_sym(inputs['newStatus'])
|
80
|
+
old_state = inputs['oldState'] || thing_status_to_sym(inputs['oldStatus'])
|
81
81
|
|
82
82
|
[new_state, old_state]
|
83
83
|
end
|
@@ -93,32 +93,6 @@ module OpenHAB
|
|
93
93
|
status&.to_s&.downcase&.to_sym
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
97
|
-
# Check the from state against the trigger delay
|
98
|
-
#
|
99
|
-
# @param [Item State] state from state to check
|
100
|
-
#
|
101
|
-
# @return [Boolean] true if no from state is defined or defined state equals supplied state
|
102
|
-
#
|
103
|
-
def check_from(state)
|
104
|
-
return @from.include?(state) if @from.is_a?(::Range)
|
105
|
-
|
106
|
-
@from.nil? || @from == state
|
107
|
-
end
|
108
|
-
|
109
|
-
#
|
110
|
-
# Check the to state against the trigger delay
|
111
|
-
#
|
112
|
-
# @param [Item State] state to-state to check
|
113
|
-
#
|
114
|
-
# @return [Boolean] true if no to state is defined or defined state equals supplied state
|
115
|
-
#
|
116
|
-
def check_to(state)
|
117
|
-
return @to.include?(state) if @to.is_a?(::Range)
|
118
|
-
|
119
|
-
@to.nil? || @to == state
|
120
|
-
end
|
121
|
-
|
122
96
|
#
|
123
97
|
# Process any matching trigger delays
|
124
98
|
#
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openhab/log/logger'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module Rules
|
8
|
+
module Triggers
|
9
|
+
#
|
10
|
+
# Module for conditions for triggers
|
11
|
+
#
|
12
|
+
module Conditions
|
13
|
+
include OpenHAB::Log
|
14
|
+
|
15
|
+
#
|
16
|
+
# This creates trigger conditions that work on procs
|
17
|
+
# @param [Proc] from Proc
|
18
|
+
# @param [Proc] to Proc
|
19
|
+
#
|
20
|
+
class Proc
|
21
|
+
include OpenHAB::Log
|
22
|
+
|
23
|
+
# Proc that doesn't check any fields
|
24
|
+
ANY = Proc.new.freeze
|
25
|
+
|
26
|
+
#
|
27
|
+
# Converts supplied ranges to procs that check range
|
28
|
+
# @param [Array] ranges objects to convert to range proc if they are ranges
|
29
|
+
# @return [Array] of procs or supplied arguments if argument was not of type Range
|
30
|
+
#
|
31
|
+
def self.range_procs(*ranges)
|
32
|
+
ranges.map { |range| range.is_a?(Range) ? range_proc(range) : range }
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Create a range proc for the supplied range object
|
37
|
+
# @param [Range] range to build proc for
|
38
|
+
#
|
39
|
+
def self.range_proc(range)
|
40
|
+
logger.trace("Creating range proc for #{range}")
|
41
|
+
lambda do |state|
|
42
|
+
logger.trace("Range proc checking if #{state} is in #{range}")
|
43
|
+
range.include? state
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Create a range proc for the supplied range object
|
49
|
+
# @param [Range] range to build proc for
|
50
|
+
#
|
51
|
+
def self.equality_proc(value)
|
52
|
+
logger.trace("Creating equality proc for #{value}")
|
53
|
+
lambda do |state|
|
54
|
+
logger.trace("Equality proc comparing #{value} against #{state}")
|
55
|
+
value == state
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Constructs a proc for the specific value type
|
61
|
+
# if the value is a proc return the proc
|
62
|
+
# if the value is a range create a range proc
|
63
|
+
# if the value is nil, return nil
|
64
|
+
# otherwise create an equality proc
|
65
|
+
# @param [Object] value to construct proc from
|
66
|
+
def self.from_value(value)
|
67
|
+
logger.trace("Creating proc for Value(#{value})")
|
68
|
+
return value if value.nil?
|
69
|
+
return value if value.is_a? ::Proc
|
70
|
+
return range_proc(value) if value.is_a? Range
|
71
|
+
|
72
|
+
equality_proc(value)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Create a new Proc Condition that executes only if procs return true
|
77
|
+
# @param [Proc] from Proc to check against from value
|
78
|
+
# @param [Proc] to Proc to check against to value
|
79
|
+
#
|
80
|
+
def initialize(from: nil, to: nil)
|
81
|
+
@from = from
|
82
|
+
@to = to
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Process rule
|
87
|
+
# @param [Hash] inputs inputs from trigger
|
88
|
+
#
|
89
|
+
def process(mod:, inputs:) # rubocop:disable Lint/UnusedMethodArgument - mod is unused here but required
|
90
|
+
logger.trace("Checking #{inputs} against condition trigger #{self}")
|
91
|
+
yield if check_from(inputs: inputs) && check_to(inputs: inputs)
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Check if from condition match the proc
|
96
|
+
# @param [Hash] inputs from trigger must be supplied if state is not supplied
|
97
|
+
# @param [String] state if supplied proc will be passed state value for comparision
|
98
|
+
# @return [true/false] depending on if from is set and matches supplied conditions
|
99
|
+
#
|
100
|
+
def check_from(inputs: nil, state: nil)
|
101
|
+
state ||= input_state(inputs, 'oldState')
|
102
|
+
logger.trace "Checking from(#{@from}) against state(#{state})"
|
103
|
+
check_proc(proc: @from, state: state)
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# Check if to conditions match the proc
|
108
|
+
# @param [Hash] inputs from trigger must be supplied if state is not supplied
|
109
|
+
# @param [String] state if supplied proc will be passed state value for comparision
|
110
|
+
# @return [true/false] depending on if from is set and matches supplied conditions
|
111
|
+
#
|
112
|
+
def check_to(inputs: nil, state: nil)
|
113
|
+
state ||= input_state(inputs, 'newState', 'state')
|
114
|
+
logger.trace "Checking to(#{@to}) against state(#{state})"
|
115
|
+
check_proc(proc: @to, state: state)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Describe the Proc Condition as a string
|
119
|
+
# @return [String] string representation of proc condition
|
120
|
+
#
|
121
|
+
def to_s
|
122
|
+
"From:(#{@from}) To:(#{@to})"
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
# Check if a field matches the proc condition
|
128
|
+
# @param [Proc] proc to call
|
129
|
+
# @param [Hash] inputs containing fields
|
130
|
+
# @param [Array] fields array of fields to extract from inputs, first one found is passed to proc
|
131
|
+
# @return [true,false] true if proc is nil or proc.call returns true, false otherwise
|
132
|
+
def check_proc(proc:, state:)
|
133
|
+
return true if proc.nil? || proc.call(state)
|
134
|
+
|
135
|
+
logger.trace("Skipped execution of rule because state #{state} evalulated false for (#{proc})")
|
136
|
+
false
|
137
|
+
end
|
138
|
+
|
139
|
+
# Get the first field from supplied fields in inputs
|
140
|
+
# @param [Hash] inputs containing fields
|
141
|
+
# @param [Array] fields array of fields to extract from inputs, first one found is returned
|
142
|
+
def input_state(inputs, *fields)
|
143
|
+
fields.map { |f| inputs[f] }.compact.first
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -42,10 +42,10 @@ module OpenHAB
|
|
42
42
|
# @return [Trigger] OpenHAB triggers
|
43
43
|
#
|
44
44
|
def update_trigger(item:, to:, attach:)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
case to
|
46
|
+
when Range then create_update_range_trigger(item: item, to: to, attach: attach)
|
47
|
+
when Proc then create_update_proc_trigger(item: item, to: to, attach: attach)
|
48
|
+
else create_update_trigger(item: item, to: to, attach: attach)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -57,9 +57,21 @@ module OpenHAB
|
|
57
57
|
# @return [Trigger] OpenHAB trigger
|
58
58
|
#
|
59
59
|
def create_update_range_trigger(item:, to:, attach:)
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
to, * = Conditions::Proc.range_procs(to)
|
61
|
+
create_update_proc_trigger(item: item, to: to, attach: attach)
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Creates a trigger with a proc condition on the 'to' field
|
66
|
+
# @param [Object] item to create changed trigger on
|
67
|
+
# @param [Object] to state restrict trigger to
|
68
|
+
# @param [Object] attach to trigger
|
69
|
+
# @return [Trigger] OpenHAB trigger
|
70
|
+
#
|
71
|
+
def create_update_proc_trigger(item:, to:, attach:)
|
72
|
+
create_update_trigger(item: item, to: nil, attach: attach).tap do |trigger|
|
73
|
+
@trigger_conditions[trigger.id] = Conditions::Proc.new(to: to)
|
74
|
+
end
|
63
75
|
end
|
64
76
|
|
65
77
|
#
|
@@ -10,8 +10,8 @@ module OpenHAB
|
|
10
10
|
DateTimeType = org.openhab.core.library.types.DateTimeType
|
11
11
|
java_import java.time.ZonedDateTime # This is needed for the addon prior to ruby_class fix (OH 3.2.0)
|
12
12
|
|
13
|
-
# global alias
|
14
|
-
::DateTimeType = DateTimeType
|
13
|
+
# global alias - required for jrubyscripting addon <= OH3.2.0
|
14
|
+
::DateTimeType = DateTimeType if ::DateTimeType.is_a?(Java::JavaLang::Class)
|
15
15
|
|
16
16
|
# @deprecated
|
17
17
|
# Backwards-compatible alias
|
@@ -8,8 +8,8 @@ module OpenHAB
|
|
8
8
|
module Types
|
9
9
|
HSBType = org.openhab.core.library.types.HSBType
|
10
10
|
|
11
|
-
# global alias
|
12
|
-
::HSBType = HSBType
|
11
|
+
# global alias - required for jrubyscripting addon <= OH3.2.0
|
12
|
+
::HSBType = HSBType if ::HSBType.is_a?(Java::JavaLang::Class)
|
13
13
|
|
14
14
|
# Adds methods to core OpenHAB HSBType to make it more natural in Ruby
|
15
15
|
class HSBType < PercentType
|
@@ -7,8 +7,8 @@ module OpenHAB
|
|
7
7
|
module Types
|
8
8
|
PercentType = org.openhab.core.library.types.PercentType
|
9
9
|
|
10
|
-
# global alias
|
11
|
-
::PercentType = PercentType
|
10
|
+
# global alias - required for jrubyscripting addon <= OH3.2.0
|
11
|
+
::PercentType = PercentType if ::PercentType.is_a?(Java::JavaLang::Class)
|
12
12
|
|
13
13
|
# Adds methods to core OpenHAB PercentType to make it more natural in Ruby
|
14
14
|
class PercentType < DecimalType
|
@@ -5,9 +5,9 @@ module OpenHAB
|
|
5
5
|
module Types
|
6
6
|
PointType = org.openhab.core.library.types.PointType
|
7
7
|
|
8
|
-
# global scope
|
8
|
+
# global scope - required for jrubyscripting addon <= OH3.2.0
|
9
9
|
# @!visibility private
|
10
|
-
::PointType = PointType
|
10
|
+
::PointType = PointType if ::PointType.is_a?(Java::JavaLang::Class)
|
11
11
|
|
12
12
|
# Adds methods to core OpenHAB PointType to make it more natural in Ruby
|
13
13
|
class PointType
|
@@ -7,8 +7,8 @@ module OpenHAB
|
|
7
7
|
module Types
|
8
8
|
QuantityType = org.openhab.core.library.types.QuantityType
|
9
9
|
|
10
|
-
# global alias
|
11
|
-
::QuantityType = QuantityType
|
10
|
+
# global alias - required for jrubyscripting addon <= OH3.2.0
|
11
|
+
::QuantityType = QuantityType if ::QuantityType.is_a?(Java::JavaLang::Class)
|
12
12
|
|
13
13
|
# @deprecated
|
14
14
|
# Backwards-compatible alias
|
@@ -20,8 +20,8 @@ module OpenHAB
|
|
20
20
|
include NumericType
|
21
21
|
|
22
22
|
# private alias
|
23
|
-
|
24
|
-
private_constant :
|
23
|
+
ONE_UNIT = org.openhab.core.library.unit.Units::ONE
|
24
|
+
private_constant :ONE_UNIT
|
25
25
|
|
26
26
|
#
|
27
27
|
# Convert this quantity into a another unit
|
@@ -46,8 +46,8 @@ module OpenHAB
|
|
46
46
|
def <=>(other) # rubocop:disable Metrics
|
47
47
|
logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
|
48
48
|
if other.is_a?(self.class)
|
49
|
-
return unitize(other.unit).compare_to(other) if unit ==
|
50
|
-
return compare_to(other.unitize(unit)) if other.unit ==
|
49
|
+
return unitize(other.unit).compare_to(other) if unit == ONE_UNIT
|
50
|
+
return compare_to(other.unitize(unit)) if other.unit == ONE_UNIT
|
51
51
|
|
52
52
|
compare_to(other)
|
53
53
|
elsif other.is_a?(Items::NumericItem) ||
|
@@ -88,7 +88,7 @@ module OpenHAB
|
|
88
88
|
elsif other.is_a?(Type)
|
89
89
|
[other, as(other.class)]
|
90
90
|
elsif other.respond_to?(:to_d)
|
91
|
-
[QuantityType.new(other.to_d.to_java,
|
91
|
+
[QuantityType.new(other.to_d.to_java, ONE_UNIT), self]
|
92
92
|
elsif other.is_a?(String)
|
93
93
|
[QuantityType.new(other), self]
|
94
94
|
end
|
@@ -215,7 +215,7 @@ module OpenHAB
|
|
215
215
|
logger.trace("Converting #{self} to #{other_unit}")
|
216
216
|
|
217
217
|
case unit
|
218
|
-
when
|
218
|
+
when ONE_UNIT
|
219
219
|
QuantityType.new(to_big_decimal, other_unit)
|
220
220
|
when other_unit
|
221
221
|
self
|
@@ -224,10 +224,10 @@ module OpenHAB
|
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
-
# if unit is +
|
227
|
+
# if unit is +ONE_UNIT+, return a plain Java BigDecimal
|
228
228
|
# @!visibility private
|
229
229
|
def deunitize
|
230
|
-
return to_big_decimal if unit ==
|
230
|
+
return to_big_decimal if unit == ONE_UNIT
|
231
231
|
|
232
232
|
self
|
233
233
|
end
|
data/lib/openhab/log/logger.rb
CHANGED
@@ -245,9 +245,8 @@ module OpenHAB
|
|
245
245
|
#
|
246
246
|
def log_caller
|
247
247
|
caller_locations.map(&:path)
|
248
|
-
.grep_v(%r{openhab/core/})
|
249
248
|
.grep_v(/rubygems/)
|
250
|
-
.grep_v(
|
249
|
+
.grep_v(/openhab-scripting/)
|
251
250
|
.first
|
252
251
|
.then { |caller| File.basename(caller, '.*') if caller }
|
253
252
|
end
|
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.30.3
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,8 +107,7 @@ files:
|
|
107
107
|
- lib/openhab/dsl/rules/triggers/channel.rb
|
108
108
|
- lib/openhab/dsl/rules/triggers/command.rb
|
109
109
|
- lib/openhab/dsl/rules/triggers/conditions/duration.rb
|
110
|
-
- lib/openhab/dsl/rules/triggers/conditions/
|
111
|
-
- lib/openhab/dsl/rules/triggers/conditions/range.rb
|
110
|
+
- lib/openhab/dsl/rules/triggers/conditions/proc.rb
|
112
111
|
- lib/openhab/dsl/rules/triggers/cron.rb
|
113
112
|
- lib/openhab/dsl/rules/triggers/generic.rb
|
114
113
|
- lib/openhab/dsl/rules/triggers/trigger.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openhab/log/logger'
|
4
|
-
require 'singleton'
|
5
|
-
|
6
|
-
module OpenHAB
|
7
|
-
module DSL
|
8
|
-
module Rules
|
9
|
-
module Triggers
|
10
|
-
#
|
11
|
-
# Module for conditions for triggers
|
12
|
-
#
|
13
|
-
module Conditions
|
14
|
-
include OpenHAB::Log
|
15
|
-
#
|
16
|
-
# this is a no-op condition which simply executes the provided block
|
17
|
-
#
|
18
|
-
class None
|
19
|
-
include Singleton
|
20
|
-
|
21
|
-
# Process rule
|
22
|
-
# @param [Hash] inputs inputs from trigger
|
23
|
-
#
|
24
|
-
def process(*)
|
25
|
-
yield
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openhab/log/logger'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
module DSL
|
7
|
-
module Rules
|
8
|
-
module Triggers
|
9
|
-
#
|
10
|
-
# Module for conditions for triggers
|
11
|
-
#
|
12
|
-
module Conditions
|
13
|
-
include OpenHAB::Log
|
14
|
-
|
15
|
-
#
|
16
|
-
# This creates trigger conditions that work on ranges
|
17
|
-
# @param [Range:] From range
|
18
|
-
# @param [To:] To range
|
19
|
-
#
|
20
|
-
class Range
|
21
|
-
def initialize(from: nil, to: nil)
|
22
|
-
@from = from
|
23
|
-
@to = to
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Process rule
|
28
|
-
# @param [Hash] inputs inputs from trigger
|
29
|
-
#
|
30
|
-
def process(mod:, inputs:) # rubocop:disable Lint/UnusedMethodArgument - mod is unused here but required
|
31
|
-
logger.trace("Checking #{inputs} against condition trigger #{self}")
|
32
|
-
yield if check_from(inputs: inputs) && check_to(inputs: inputs)
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Check if from condition match the inputs
|
37
|
-
# @param [Hash] inputs inputs from trigger
|
38
|
-
# @return [true/false] depending on if from is set and matches supplied conditions
|
39
|
-
#
|
40
|
-
def check_from(inputs:)
|
41
|
-
old_state = inputs['oldState']
|
42
|
-
return true if @from.nil? || @from.include?(old_state)
|
43
|
-
|
44
|
-
logger.trace("Skipped execution of rule because old state #{old_state}"\
|
45
|
-
" does not equal specified range(#{@from})")
|
46
|
-
false
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# Check if to conditions match the inputs
|
51
|
-
# @param [Hash] inputs inputs from trigger
|
52
|
-
# @return [true/false] depending on if from is set and matches supplied conditions
|
53
|
-
#
|
54
|
-
def check_to(inputs:)
|
55
|
-
new_state = inputs['newState'] || inputs['state'] # Get state for changed or update
|
56
|
-
return true if @to.nil? || @to.include?(new_state)
|
57
|
-
|
58
|
-
logger.trace("Skipped execution of rule because new state #{new_state}"\
|
59
|
-
" does not equal specified range(#{@to})")
|
60
|
-
false
|
61
|
-
end
|
62
|
-
|
63
|
-
# Describe the Range Condition as a string
|
64
|
-
# @return [String] string representation of range condition
|
65
|
-
#
|
66
|
-
def to_s
|
67
|
-
"From:(#{@from}) To:(#{@to})"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|