openhab-scripting 2.10.0 → 2.13.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/dsl/gems.rb +1 -26
- data/lib/openhab/core/dsl/items/items.rb +10 -0
- data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +42 -0
- data/lib/openhab/core/dsl/rule/item.rb +1 -0
- data/lib/openhab/core/dsl/rule/rule.rb +18 -1
- data/lib/openhab/core/duration.rb +9 -0
- data/lib/openhab/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e3db2fe066cd7fe8c314eda96c2ce182611c1af9be801fb179896eaeebbca6e
|
4
|
+
data.tar.gz: a91ab773ddff831028cf3ef9839cca92f8772f3e9c10eb6c49d610282a4f998b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7ada2d4a291c47f44531f47e7556799c800f83ec9fa2d23d3cd708ddba11bd958a84d0df74c999ca49e0f14f5f9067a7a5c7d5ac766bab31bdc5e969bab236f
|
7
|
+
data.tar.gz: b06aae6303a62bf4b53144c9cf0e1ad0d2457be0a76e1930f1558d156259ccd1dbe89ed9a1121c1ffb0a728052665c57cc5736ed1932d78cc61ff88bbdcc2c24
|
@@ -1,29 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'core/log'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'bundler/inline'
|
7
|
-
|
8
|
-
include Logging
|
9
|
-
logger.debug('Bundler required')
|
10
|
-
rescue LoadError
|
11
|
-
include Logging
|
12
|
-
logger.debug('Bundler not found installing')
|
13
|
-
|
14
|
-
begin
|
15
|
-
require 'rubygems/commands/install_command'
|
16
|
-
cmd = Gem::Commands::InstallCommand.new
|
17
|
-
cmd.handle_options ['--no-document', 'bundler', '-v', '2.1.4']
|
18
|
-
cmd.execute
|
19
|
-
logger.debug('Bundler is installed')
|
20
|
-
require 'bundler/inline'
|
21
|
-
rescue Gem::SystemExitException => e
|
22
|
-
if e.exit_code.zero?
|
23
|
-
logger.debug('Bundler is installed')
|
24
|
-
require 'bundler/inline'
|
25
|
-
else
|
26
|
-
logger.error("Error installing bundler, exit code: #{e}")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
4
|
+
require 'bundler/inline'
|
@@ -22,7 +22,17 @@ module OpenHAB
|
|
22
22
|
item = $ir.getItem(name)
|
23
23
|
# rubocop: enable Style/GlobalVars
|
24
24
|
(item.is_a? GroupItem) ? nil : item
|
25
|
+
rescue Java::OrgOpenhabCoreItems::ItemNotFoundException
|
26
|
+
nil
|
25
27
|
end
|
28
|
+
|
29
|
+
# Returns true if the given item name exists
|
30
|
+
# @param name [String] Item name to check
|
31
|
+
# @return [Boolean] true if the item exists, false otherwise
|
32
|
+
def include?(name)
|
33
|
+
!$ir.getItems(name).empty?
|
34
|
+
end
|
35
|
+
alias key? include?
|
26
36
|
end
|
27
37
|
|
28
38
|
java_import org.openhab.core.items.GroupItem
|
@@ -14,6 +14,7 @@ Dimmer = DimmerItem
|
|
14
14
|
#
|
15
15
|
# rubocop:disable Style/ClassAndModuleChildren
|
16
16
|
class Java::OrgOpenhabCoreLibraryItems::DimmerItem
|
17
|
+
include Comparable
|
17
18
|
# rubocop:enable Style/ClassAndModuleChildren
|
18
19
|
java_import org.openhab.core.library.types.DecimalType
|
19
20
|
java_import org.openhab.core.library.types.IncreaseDecreaseType
|
@@ -85,6 +86,38 @@ class Java::OrgOpenhabCoreLibraryItems::DimmerItem
|
|
85
86
|
target
|
86
87
|
end
|
87
88
|
|
89
|
+
#
|
90
|
+
# Compare DimmerItem to supplied object
|
91
|
+
#
|
92
|
+
# @param [Object] other object to compare to
|
93
|
+
#
|
94
|
+
# @return [Integer] -1,0,1 or nil depending on value supplied, nil comparison to supplied object is not possible.
|
95
|
+
#
|
96
|
+
def <=>(other)
|
97
|
+
logger.trace("Comparing #{self} to #{other}")
|
98
|
+
case other
|
99
|
+
when DimmerItem, NumberItem
|
100
|
+
state <=> other.state
|
101
|
+
when DecimalType
|
102
|
+
state <=> other
|
103
|
+
else
|
104
|
+
to_i <=> other.to_i
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Compare DimmerItem to supplied object.
|
110
|
+
# The == operator needs to be overridden because the parent java object
|
111
|
+
# has .equals which overrides the <=> operator above
|
112
|
+
#
|
113
|
+
# @param [Object] other object to compare to
|
114
|
+
#
|
115
|
+
# @return [Integer] true if the two objects contain the same value, false otherwise
|
116
|
+
#
|
117
|
+
def ==(other)
|
118
|
+
(self <=> other).zero?
|
119
|
+
end
|
120
|
+
|
88
121
|
#
|
89
122
|
# Check if dimmer has a state and state is not zero
|
90
123
|
#
|
@@ -105,6 +138,15 @@ class Java::OrgOpenhabCoreLibraryItems::DimmerItem
|
|
105
138
|
|
106
139
|
alias to_int to_i
|
107
140
|
|
141
|
+
#
|
142
|
+
# Return the string representation of the dimmer item
|
143
|
+
#
|
144
|
+
# @return [String] String version of the dimmer value
|
145
|
+
#
|
146
|
+
def to_s
|
147
|
+
to_i.to_s
|
148
|
+
end
|
149
|
+
|
108
150
|
#
|
109
151
|
# Check if dimmer is on
|
110
152
|
#
|
@@ -303,6 +303,23 @@ module OpenHAB
|
|
303
303
|
false
|
304
304
|
end
|
305
305
|
|
306
|
+
#
|
307
|
+
# Patch event to include event.item when it doesn't exist
|
308
|
+
# This is to patch a bug see https://github.com/boc-tothefuture/openhab-jruby/issues/75
|
309
|
+
# It may be fixed in the openhab core in the future, in which case, this patch will no longer be necessary
|
310
|
+
#
|
311
|
+
# @param [OpenHAB Event] event to check for item accessor
|
312
|
+
# @param [OpenHAB Event Inputs] inputs inputs to running rule
|
313
|
+
#
|
314
|
+
def add_event_item(event, inputs)
|
315
|
+
return if event.nil? || defined?(event.item)
|
316
|
+
|
317
|
+
class << event
|
318
|
+
attr_accessor :item
|
319
|
+
end
|
320
|
+
event.item = inputs&.dig('triggeringItem')
|
321
|
+
end
|
322
|
+
|
306
323
|
#
|
307
324
|
# Process the run queue
|
308
325
|
#
|
@@ -317,7 +334,7 @@ module OpenHAB
|
|
317
334
|
when RuleConfig::Run
|
318
335
|
|
319
336
|
event = inputs&.dig('event')
|
320
|
-
|
337
|
+
add_event_item(event, inputs)
|
321
338
|
logger.trace { "Executing rule '#{name}' run block with event(#{event})" }
|
322
339
|
task.block.call(event)
|
323
340
|
when RuleConfig::Trigger
|
@@ -64,6 +64,15 @@ module OpenHAB
|
|
64
64
|
@amount * 1000 * 60 * 60
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Return a string representation of the duration
|
70
|
+
#
|
71
|
+
# @return [String] Duration in string
|
72
|
+
#
|
73
|
+
def to_s
|
74
|
+
"#{@amount} #{(@amount == 1) ? @temporal_unit.to_s.downcase.delete_suffix('s') : @temporal_unit.to_s.downcase}"
|
75
|
+
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
data/lib/openhab/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.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-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
13
27
|
description: JRuby Helper Libraries for OpenHAB Scripting
|
14
28
|
email:
|
15
29
|
- broconne@gmail.com
|