openhab-scripting 2.16.2 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab.rb +12 -16
- data/lib/openhab/core/entity_lookup.rb +173 -0
- data/lib/openhab/core/openhab_setup.rb +31 -0
- data/lib/openhab/core/osgi.rb +61 -0
- data/lib/openhab/dsl/actions.rb +105 -0
- data/lib/openhab/dsl/dsl.rb +49 -0
- data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
- data/lib/openhab/dsl/group.rb +100 -0
- data/lib/openhab/dsl/items/datetime_item.rb +97 -0
- data/lib/openhab/dsl/items/items.rb +46 -0
- data/lib/openhab/dsl/items/number_item.rb +352 -0
- data/lib/openhab/dsl/items/rollershutter_item.rb +179 -0
- data/lib/openhab/dsl/items/string_item.rb +120 -0
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
- data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
- data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
- data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
- data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
- data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
- data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +8 -0
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
- data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
- data/lib/openhab/dsl/monkey_patch/types/types.rb +9 -0
- data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +33 -0
- data/lib/openhab/dsl/persistence.rb +25 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
- data/lib/openhab/dsl/rules/guard.rb +134 -0
- data/lib/openhab/dsl/rules/property.rb +102 -0
- data/lib/openhab/dsl/rules/rule.rb +116 -0
- data/lib/openhab/dsl/rules/rule_config.rb +151 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
- data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
- data/lib/openhab/dsl/states.rb +61 -0
- data/lib/openhab/dsl/things.rb +91 -0
- data/lib/openhab/dsl/time_of_day.rb +232 -0
- data/lib/openhab/dsl/timers.rb +77 -0
- data/lib/openhab/dsl/types/datetime.rb +326 -0
- data/lib/openhab/dsl/types/quantity.rb +290 -0
- data/lib/openhab/dsl/units.rb +39 -0
- data/lib/openhab/log/configuration.rb +21 -0
- data/lib/openhab/log/logger.rb +172 -0
- data/lib/openhab/version.rb +1 -1
- metadata +60 -58
- data/lib/openhab/configuration.rb +0 -16
- data/lib/openhab/core/cron.rb +0 -27
- data/lib/openhab/core/debug.rb +0 -34
- data/lib/openhab/core/dsl.rb +0 -51
- data/lib/openhab/core/dsl/actions.rb +0 -107
- data/lib/openhab/core/dsl/entities.rb +0 -147
- data/lib/openhab/core/dsl/group.rb +0 -102
- data/lib/openhab/core/dsl/items/items.rb +0 -51
- data/lib/openhab/core/dsl/items/number_item.rb +0 -323
- data/lib/openhab/core/dsl/items/string_item.rb +0 -122
- data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
- data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
- data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
- data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
- data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
- data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
- data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
- data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
- data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
- data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
- data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
- data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
- data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
- data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
- data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
- data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
- data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
- data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
- data/lib/openhab/core/dsl/persistence.rb +0 -27
- data/lib/openhab/core/dsl/property.rb +0 -96
- data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
- data/lib/openhab/core/dsl/rule/guard.rb +0 -136
- data/lib/openhab/core/dsl/rule/rule.rb +0 -117
- data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
- data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
- data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
- data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
- data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
- data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
- data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
- data/lib/openhab/core/dsl/states.rb +0 -63
- data/lib/openhab/core/dsl/things.rb +0 -93
- data/lib/openhab/core/dsl/time_of_day.rb +0 -231
- data/lib/openhab/core/dsl/timers.rb +0 -79
- data/lib/openhab/core/dsl/types/quantity.rb +0 -292
- data/lib/openhab/core/dsl/units.rb +0 -41
- data/lib/openhab/core/log.rb +0 -170
- data/lib/openhab/core/patch_load_path.rb +0 -7
- data/lib/openhab/core/startup_delay.rb +0 -23
- data/lib/openhab/osgi.rb +0 -59
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'java'
|
5
|
+
|
6
|
+
module OpenHAB
|
7
|
+
module DSL
|
8
|
+
module Items
|
9
|
+
#
|
10
|
+
# Delegator to OpenHAB Rollershutter Item
|
11
|
+
#
|
12
|
+
class RollershutterItem < Numeric
|
13
|
+
extend Forwardable
|
14
|
+
include Comparable
|
15
|
+
|
16
|
+
def_delegator :@rollershutter_item, :to_s
|
17
|
+
|
18
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::PercentType
|
19
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::UpDownType
|
20
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::StopMoveType
|
21
|
+
|
22
|
+
#
|
23
|
+
# Creates a new RollershutterItem
|
24
|
+
#
|
25
|
+
# @param [Java::OrgOpenhabCoreLibraryItems::RollershutterItem] rollershutter_item
|
26
|
+
# The OpenHAB RollershutterItem to delegate to
|
27
|
+
#
|
28
|
+
def initialize(rollershutter_item)
|
29
|
+
logger.trace("Wrapping #{rollershutter_item}")
|
30
|
+
@rollershutter_item = rollershutter_item
|
31
|
+
|
32
|
+
super()
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Check if the rollershutter is up
|
37
|
+
#
|
38
|
+
# @return [Boolean] true if the rollershutter is up, false otherwise
|
39
|
+
#
|
40
|
+
def up?
|
41
|
+
state.as(UpDownType) == UpDownType::UP
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Check if the rollershutter is down
|
46
|
+
#
|
47
|
+
# @return [Boolean] true if the rollershutter is down, false otherwise
|
48
|
+
#
|
49
|
+
def down?
|
50
|
+
state.as(UpDownType) == UpDownType::DOWN
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Returns the rollershutter's position
|
55
|
+
#
|
56
|
+
# @return [Java::OrgOpenhabCoreLibraryTypes::PercentType] the position of the rollershutter
|
57
|
+
#
|
58
|
+
def position
|
59
|
+
state.as(PercentType)
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Compare the rollershutter's position against another object
|
64
|
+
#
|
65
|
+
# @param [Object] other object to compare against
|
66
|
+
#
|
67
|
+
# @return [Integer] -1, 0 or 1 depending on the result of the comparison
|
68
|
+
#
|
69
|
+
def <=>(other)
|
70
|
+
case other
|
71
|
+
when PercentType, Java::OrgOpenhabCoreLibraryTypes::DecimalType then position.compare_to(other)
|
72
|
+
when Numeric then position.int_value <=> other
|
73
|
+
when RollershutterItem then position.compare_to(other.position)
|
74
|
+
when UpDownType then state.as(UpDownType) == other
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Coerce self into other to enable calculations
|
80
|
+
#
|
81
|
+
# @param [Numeric] other Other numeric to coerce into
|
82
|
+
#
|
83
|
+
# @return [Array<Numeric>] an array of other and self coerced into other's type
|
84
|
+
#
|
85
|
+
def coerce(other)
|
86
|
+
raise ArgumentError, "Cannot coerce to #{other.class}" unless other.is_a? Numeric
|
87
|
+
|
88
|
+
case other
|
89
|
+
when Integer then [other, position.int_value]
|
90
|
+
when Float then [other, position.float_value]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Case equality
|
96
|
+
#
|
97
|
+
# @param [Java::OrgOpenhabCoreLibraryTypes::UpDownType, Numeric] other Other object to compare against
|
98
|
+
#
|
99
|
+
# @return [Boolean] true if self can be defined as other, false otherwise
|
100
|
+
#
|
101
|
+
def ===(other)
|
102
|
+
super unless other.is_a? UpDownType
|
103
|
+
|
104
|
+
state.as(UpDownType).equals(other)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Sends an UP command to the Item
|
109
|
+
#
|
110
|
+
def up
|
111
|
+
command UpDownType::UP
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Sends a DOWN command to the Item
|
116
|
+
#
|
117
|
+
def down
|
118
|
+
command UpDownType::DOWN
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# Sends a STOP command to the Item
|
123
|
+
#
|
124
|
+
def stop
|
125
|
+
command StopMoveType::STOP
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Sends a MOVE command to the Item
|
130
|
+
#
|
131
|
+
def move
|
132
|
+
command StopMoveType::MOVE
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Define math operations
|
137
|
+
#
|
138
|
+
%i[+ - * / %].each do |operator|
|
139
|
+
define_method(operator) do |other|
|
140
|
+
right, left = coerce(other)
|
141
|
+
left.send(operator, right)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Checks if this method responds to the missing method
|
147
|
+
#
|
148
|
+
# @param [String] meth Name of the method to check
|
149
|
+
# @param [Boolean] _include_private boolean if private methods should be checked
|
150
|
+
#
|
151
|
+
# @return [Boolean] true if this object will respond to the supplied method, false otherwise
|
152
|
+
#
|
153
|
+
def respond_to_missing?(meth, _include_private = false)
|
154
|
+
@rollershutter_item.respond_to?(meth) || position.respond_to?(meth)
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Forward missing methods to Openhab RollershutterItem or the PercentType representing it's state
|
159
|
+
# if they are defined
|
160
|
+
#
|
161
|
+
# @param [String] meth method name
|
162
|
+
# @param [Array] args arguments for method
|
163
|
+
# @param [Proc] block <description>
|
164
|
+
#
|
165
|
+
# @return [Object] Value from delegated method in OpenHAB NumberItem
|
166
|
+
#
|
167
|
+
def method_missing(meth, *args, &block)
|
168
|
+
if @rollershutter_item.respond_to?(meth)
|
169
|
+
@rollershutter_item.__send__(meth, *args, &block)
|
170
|
+
elsif position.respond_to?(meth)
|
171
|
+
position.__send__(meth, *args, &block)
|
172
|
+
else
|
173
|
+
raise NoMethodError, "No method `#{meth}' defined for #{self.class}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'java'
|
6
|
+
|
7
|
+
module OpenHAB
|
8
|
+
module DSL
|
9
|
+
module Items
|
10
|
+
#
|
11
|
+
# Delegator to OpenHAB String Item
|
12
|
+
#
|
13
|
+
class StringItem
|
14
|
+
extend Forwardable
|
15
|
+
include Comparable
|
16
|
+
|
17
|
+
# @return [Regex] Regular expression matching blank strings
|
18
|
+
BLANK_RE = /\A[[:space:]]*\z/.freeze
|
19
|
+
private_constant :BLANK_RE
|
20
|
+
|
21
|
+
def_delegator :@string_item, :to_s
|
22
|
+
|
23
|
+
#
|
24
|
+
# Create a new StringItem
|
25
|
+
#
|
26
|
+
# @param [Java::Org::openhab::core::library::items::StringItem] string_item OpenHAB string item to delegate to
|
27
|
+
#
|
28
|
+
def initialize(string_item)
|
29
|
+
@string_item = string_item
|
30
|
+
super()
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Convert the StringItem into a String
|
35
|
+
#
|
36
|
+
# @return [String] String representation of the StringItem or
|
37
|
+
# nil if underlying OpenHAB StringItem does not have a state
|
38
|
+
#
|
39
|
+
def to_str
|
40
|
+
@string_item.state&.to_full_string&.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Detect if the string is blank (not set or only whitespace)
|
45
|
+
#
|
46
|
+
# @return [Boolean] True if string item is not set or contains only whitespace, false otherwise
|
47
|
+
#
|
48
|
+
def blank?
|
49
|
+
return true unless @string_item.state?
|
50
|
+
|
51
|
+
@string_item.state.to_full_string.to_s.empty? || BLANK_RE.match?(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Check if StringItem is truthy? as per defined by library
|
56
|
+
#
|
57
|
+
# @return [Boolean] True if item is not in state UNDEF or NULL and value is not blank
|
58
|
+
#
|
59
|
+
def truthy?
|
60
|
+
@string_item.state? && blank? == false
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Compare StringItem to supplied object
|
65
|
+
#
|
66
|
+
# @param [Object] other object to compare to
|
67
|
+
#
|
68
|
+
# @return [Integer] -1,0,1 or nil depending on value supplied,
|
69
|
+
# nil comparison to supplied object is not possible.
|
70
|
+
#
|
71
|
+
def <=>(other)
|
72
|
+
case other
|
73
|
+
when StringItem
|
74
|
+
@string_item.state <=> other.state
|
75
|
+
when String
|
76
|
+
@string_item.state.to_s <=> other
|
77
|
+
else
|
78
|
+
@string_item.state <=> other
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Forward missing methods to Openhab String Item or String representation of the item if they are defined
|
84
|
+
#
|
85
|
+
# @param [String] meth method name
|
86
|
+
# @param [Array] args arguments for method
|
87
|
+
# @param [Proc] block <description>
|
88
|
+
#
|
89
|
+
# @return [Object] Value from delegated method in OpenHAB StringItem or Ruby String
|
90
|
+
#
|
91
|
+
def method_missing(meth, *args, &block)
|
92
|
+
if @string_item.respond_to?(meth)
|
93
|
+
@string_item.__send__(meth, *args, &block)
|
94
|
+
elsif @string_item.state&.to_full_string&.to_s.respond_to?(meth)
|
95
|
+
@string_item.state.to_full_string.to_s.__send__(meth, *args, &block)
|
96
|
+
elsif ::Kernel.method_defined?(meth) || ::Kernel.private_method_defined?(meth)
|
97
|
+
::Kernel.instance_method(meth).bind_call(self, *args, &block)
|
98
|
+
else
|
99
|
+
super(meth, *args, &block)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Checks if this method responds to the missing method
|
105
|
+
#
|
106
|
+
# @param [String] method_name Name of the method to check
|
107
|
+
# @param [Boolean] _include_private boolean if private methods should be checked
|
108
|
+
#
|
109
|
+
# @return [Boolean] true if this object will respond to the supplied method, false otherwise
|
110
|
+
#
|
111
|
+
def respond_to_missing?(method_name, _include_private = false)
|
112
|
+
@string_item.respond_to?(method_name) ||
|
113
|
+
@string_item.state&.to_full_string&.to_s.respond_to?(method_name) ||
|
114
|
+
::Kernel.method_defined?(method_name) ||
|
115
|
+
::Kernel.private_method_defined?(method_name)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB actions
|
10
|
+
#
|
11
|
+
module Actions
|
12
|
+
java_import Java::OrgOpenhabCoreAutomationModuleScriptInternalDefaultscope::ScriptThingActions
|
13
|
+
|
14
|
+
#
|
15
|
+
# MonkeyPatching ScriptThingActions
|
16
|
+
#
|
17
|
+
class ScriptThingActions
|
18
|
+
field_reader :THING_ACTIONS_MAP
|
19
|
+
|
20
|
+
#
|
21
|
+
# Fetch keys for all actions defined in OpenHAB
|
22
|
+
#
|
23
|
+
# @return [Set] of keys for defined actions in the form of 'scope-thing_uid'
|
24
|
+
#
|
25
|
+
def action_keys
|
26
|
+
ScriptThingActions.THING_ACTIONS_MAP.keys
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB events
|
10
|
+
#
|
11
|
+
module Events
|
12
|
+
java_import Java::OrgOpenhabCoreItemsEvents::ItemCommandEvent
|
13
|
+
|
14
|
+
#
|
15
|
+
# Monkey patch with ruby style accesors
|
16
|
+
#
|
17
|
+
class ItemCommandEvent
|
18
|
+
alias command item_command
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB events
|
10
|
+
#
|
11
|
+
module Events
|
12
|
+
java_import Java::OrgOpenhabCoreItemsEvents::ItemStateChangedEvent
|
13
|
+
|
14
|
+
#
|
15
|
+
# MonkeyPatch with ruby style accessors
|
16
|
+
#
|
17
|
+
class ItemStateChangedEvent
|
18
|
+
#
|
19
|
+
# Get the item that caused the state change
|
20
|
+
#
|
21
|
+
# @return [Item] Item that caused state change
|
22
|
+
#
|
23
|
+
def item
|
24
|
+
# rubocop:disable Style/GlobalVars
|
25
|
+
$ir.get(item_name)
|
26
|
+
# rubocop:enable Style/GlobalVars
|
27
|
+
end
|
28
|
+
|
29
|
+
alias state item_state
|
30
|
+
alias last old_item_state
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB events
|
10
|
+
#
|
11
|
+
module Event
|
12
|
+
java_import Java::OrgOpenhabCoreThingEvents::ThingStatusInfoChangedEvent
|
13
|
+
java_import Java::OrgOpenhabCoreThingEvents::ThingStatusInfoEvent
|
14
|
+
#
|
15
|
+
# Monkey patch with ruby style accessors
|
16
|
+
#
|
17
|
+
class ThingStatusInfoChangedEvent
|
18
|
+
alias uid get_thing_uid
|
19
|
+
alias last get_old_status_info
|
20
|
+
alias status status_info
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Monkey patch with ruby style accessors
|
25
|
+
#
|
26
|
+
class ThingStatusInfoEvent
|
27
|
+
alias uid get_thing_uid
|
28
|
+
alias status status_info
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB items
|
10
|
+
#
|
11
|
+
module Items
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryItems::ContactItem
|
13
|
+
|
14
|
+
#
|
15
|
+
# Alias class for ContactItem
|
16
|
+
#
|
17
|
+
::Contact = ContactItem
|
18
|
+
|
19
|
+
#
|
20
|
+
# Monkey patch Contact Item with Ruby methods
|
21
|
+
#
|
22
|
+
class ContactItem
|
23
|
+
java_import org.openhab.core.library.types.OpenClosedType
|
24
|
+
#
|
25
|
+
# Check if the contact is open
|
26
|
+
#
|
27
|
+
# @return [Boolean] True if contact has state and is open, false otherwise
|
28
|
+
#
|
29
|
+
def open?
|
30
|
+
state? && state == OpenClosedType::OPEN
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Check if the contact is closed
|
35
|
+
#
|
36
|
+
# @return [Boolean] True if contact has state and is closed, false otherwise
|
37
|
+
#
|
38
|
+
def closed?
|
39
|
+
state? && state == OpenClosedType::CLOSED
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Compares contacts to OpenClosedTypes
|
44
|
+
#
|
45
|
+
# @param [Object] other object to compare to
|
46
|
+
#
|
47
|
+
# @return [Boolean] True if contact has a state and state equals other, nil if no state,
|
48
|
+
# result from super if not supplied an OpenClosedType
|
49
|
+
#
|
50
|
+
def ==(other)
|
51
|
+
if other.is_a? OpenClosedType
|
52
|
+
state? && state == other
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|