openhab-scripting 3.1.2 → 3.4.1
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/datetime_item.rb +1 -0
- data/lib/openhab/dsl/items/image_item.rb +4 -3
- data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +2 -0
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +18 -1
- data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +2 -0
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +4 -1
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +15 -0
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +15 -0
- data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +15 -0
- data/lib/openhab/dsl/rules/triggers/cron.rb +1 -4
- data/lib/openhab/dsl/things.rb +17 -0
- data/lib/openhab/dsl/types/datetime.rb +6 -6
- data/lib/openhab/log/logger.rb +20 -3
- data/lib/openhab/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3dc9b053a3ac139909642f0e790a231dbd4e0b370a94836b740af22283f60315
|
|
4
|
+
data.tar.gz: 9debccaf47bdf3d8b4c80e05d861d3e43f658f22ad569a9f60acf7a214bc0f37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f04e70a4126f41f204b803617e757d66fe8e03f50543cc0a7a5c6c046b3567178f32d6cc6b97fbd9f0b0ca8b90c8c1fceb75b855bfe5565d4b8b7c8732e2efb8
|
|
7
|
+
data.tar.gz: 5b2092565032d2431b488250d6dc442178ecab80642f86495f56f2f199f5b05cae2f48a78b53dea118043f96c174811a0705af5596b26c9b784d315cd0bb720d
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'base64'
|
|
4
|
+
require 'pathname'
|
|
4
5
|
require 'net/http'
|
|
5
6
|
require 'java'
|
|
6
|
-
require '
|
|
7
|
+
require 'marcel'
|
|
7
8
|
require 'openhab/dsl/items/item_command'
|
|
8
9
|
require 'openhab/dsl/items/item_delegate'
|
|
9
10
|
|
|
@@ -57,7 +58,7 @@ module OpenHAB
|
|
|
57
58
|
#
|
|
58
59
|
def update_from_file(file, mime_type: nil)
|
|
59
60
|
file_data = IO.binread(file)
|
|
60
|
-
mime_type ||= (
|
|
61
|
+
mime_type ||= Marcel::MimeType.for(Pathname.new(file)) || Marcel::MimeType.for(file_data)
|
|
61
62
|
update_from_bytes(file_data, mime_type: mime_type)
|
|
62
63
|
end
|
|
63
64
|
|
|
@@ -130,7 +131,7 @@ module OpenHAB
|
|
|
130
131
|
#
|
|
131
132
|
def detect_mime_from_bytes(bytes:)
|
|
132
133
|
logger.trace('Detecting mime type from file image contents')
|
|
133
|
-
|
|
134
|
+
Marcel::MimeType.for(bytes)
|
|
134
135
|
end
|
|
135
136
|
end
|
|
136
137
|
end
|
|
@@ -9,6 +9,18 @@ module OpenHAB
|
|
|
9
9
|
#
|
|
10
10
|
module Persistence
|
|
11
11
|
java_import Java::OrgOpenhabCoreTypesUtil::UnitUtils
|
|
12
|
+
|
|
13
|
+
# A wrapper for OpenHAB's HistoricItem that returns the state directly
|
|
14
|
+
class HistoricState < SimpleDelegator
|
|
15
|
+
attr_reader :timestamp, :state
|
|
16
|
+
|
|
17
|
+
def initialize(state, timestamp)
|
|
18
|
+
@state = state
|
|
19
|
+
@timestamp = timestamp
|
|
20
|
+
super(@state)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
12
24
|
# All persistence methods that could return a Quantity
|
|
13
25
|
QUANTITY_METHODS = %i[average_since
|
|
14
26
|
delta_since
|
|
@@ -45,13 +57,18 @@ module OpenHAB
|
|
|
45
57
|
#
|
|
46
58
|
def previous_state(service = nil, skip_equal: false)
|
|
47
59
|
service ||= persistence_service
|
|
48
|
-
PersistenceExtensions.previous_state(self, skip_equal, service&.to_s)
|
|
60
|
+
result = PersistenceExtensions.previous_state(self, skip_equal, service&.to_s)
|
|
61
|
+
HistoricState.new(quantify(result.state), result.timestamp)
|
|
49
62
|
end
|
|
50
63
|
|
|
51
64
|
PERSISTENCE_METHODS.each do |method|
|
|
52
65
|
define_method(method) do |timestamp, service = nil|
|
|
53
66
|
service ||= persistence_service
|
|
54
67
|
result = PersistenceExtensions.public_send(method, self, to_zdt(timestamp), service&.to_s)
|
|
68
|
+
if result.is_a? Java::OrgOpenhabCorePersistence::HistoricItem
|
|
69
|
+
return HistoricState.new(quantify(result.state), result.timestamp)
|
|
70
|
+
end
|
|
71
|
+
|
|
55
72
|
QUANTITY_METHODS.include?(method) ? quantify(result) : result
|
|
56
73
|
end
|
|
57
74
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'openhab/dsl/types/quantity'
|
|
4
|
+
require 'openhab/dsl/types/datetime'
|
|
5
|
+
require 'openhab/dsl/items/datetime_item'
|
|
4
6
|
|
|
5
7
|
module OpenHAB
|
|
6
8
|
module DSL
|
|
@@ -21,7 +23,8 @@ module OpenHAB
|
|
|
21
23
|
#
|
|
22
24
|
def ==(other)
|
|
23
25
|
case other
|
|
24
|
-
when OpenHAB::DSL::Types::Quantity, QuantityType, Java::OrgOpenhabCoreLibraryTypes::StringType
|
|
26
|
+
when OpenHAB::DSL::Types::Quantity, QuantityType, Java::OrgOpenhabCoreLibraryTypes::StringType,
|
|
27
|
+
OpenHAB::DSL::Types::DateTime, OpenHAB::DSL::Items::DateTimeItem
|
|
25
28
|
other == self
|
|
26
29
|
else
|
|
27
30
|
super
|
|
@@ -44,6 +44,21 @@ module OpenHAB
|
|
|
44
44
|
end
|
|
45
45
|
# rubocop:enable Style/CaseLikeIf
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
# Test for equality
|
|
50
|
+
#
|
|
51
|
+
# @param [Object] other Other object to compare against
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean] true if self and other can be considered equal, false otherwise
|
|
54
|
+
#
|
|
55
|
+
def ==(other)
|
|
56
|
+
if other.respond_to?(:get_state_as)
|
|
57
|
+
self == other.get_state_as(OnOffType)
|
|
58
|
+
else
|
|
59
|
+
super
|
|
60
|
+
end
|
|
61
|
+
end
|
|
47
62
|
end
|
|
48
63
|
end
|
|
49
64
|
end
|
|
@@ -33,6 +33,21 @@ module OpenHAB
|
|
|
33
33
|
super
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Test for equality
|
|
39
|
+
#
|
|
40
|
+
# @param [Object] other Other object to compare against
|
|
41
|
+
#
|
|
42
|
+
# @return [Boolean] true if self and other can be considered equal, false otherwise
|
|
43
|
+
#
|
|
44
|
+
def ==(other)
|
|
45
|
+
if other.respond_to?(:get_state_as)
|
|
46
|
+
self == other.get_state_as(OpenClosedType)
|
|
47
|
+
else
|
|
48
|
+
super
|
|
49
|
+
end
|
|
50
|
+
end
|
|
36
51
|
end
|
|
37
52
|
end
|
|
38
53
|
end
|
|
@@ -30,6 +30,21 @@ module OpenHAB
|
|
|
30
30
|
super
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Test for equality
|
|
36
|
+
#
|
|
37
|
+
# @param [Object] other Other object to compare against
|
|
38
|
+
#
|
|
39
|
+
# @return [Boolean] true if self and other can be considered equal, false otherwise
|
|
40
|
+
#
|
|
41
|
+
def ==(other)
|
|
42
|
+
if other.respond_to?(:get_state_as)
|
|
43
|
+
self == other.get_state_as(UpDownType)
|
|
44
|
+
else
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
end
|
|
33
48
|
end
|
|
34
49
|
end
|
|
35
50
|
end
|
|
@@ -30,11 +30,8 @@ module OpenHAB
|
|
|
30
30
|
dow: '?'
|
|
31
31
|
}
|
|
32
32
|
end
|
|
33
|
-
|
|
34
|
-
# the method definition
|
|
35
|
-
# rubocop:disable Style/AccessModifierDeclarations
|
|
33
|
+
|
|
36
34
|
module_function :cron_expression_map
|
|
37
|
-
# rubocop:enable Style/AccessModifierDeclarations
|
|
38
35
|
|
|
39
36
|
# @return [Hash] Map of days of the week from symbols to to OpenHAB cron strings
|
|
40
37
|
DAY_OF_WEEK_MAP = {
|
data/lib/openhab/dsl/things.rb
CHANGED
|
@@ -11,6 +11,7 @@ module OpenHAB
|
|
|
11
11
|
# Support for OpenHAB Things
|
|
12
12
|
#
|
|
13
13
|
module Things
|
|
14
|
+
java_import Java::OrgOpenhabCoreThing::ThingStatus
|
|
14
15
|
include OpenHAB::Log
|
|
15
16
|
|
|
16
17
|
#
|
|
@@ -25,6 +26,22 @@ module OpenHAB
|
|
|
25
26
|
define_action_methods
|
|
26
27
|
end
|
|
27
28
|
|
|
29
|
+
#
|
|
30
|
+
# Defines boolean thing status methods
|
|
31
|
+
# uninitialized?
|
|
32
|
+
# initializing?
|
|
33
|
+
# unknown?
|
|
34
|
+
# online?
|
|
35
|
+
# offline?
|
|
36
|
+
# removing?
|
|
37
|
+
# removed?
|
|
38
|
+
#
|
|
39
|
+
# @return [Boolean] true if the thing status matches the name
|
|
40
|
+
#
|
|
41
|
+
ThingStatus.constants.each do |thingstatus|
|
|
42
|
+
define_method("#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
|
|
43
|
+
end
|
|
44
|
+
|
|
28
45
|
private
|
|
29
46
|
|
|
30
47
|
java_import 'org.openhab.core.automation.annotation.RuleAction'
|
|
@@ -75,13 +75,13 @@ module OpenHAB
|
|
|
75
75
|
# @return [Integer] -1, 0 or 1 depending on the outcome
|
|
76
76
|
#
|
|
77
77
|
def <=>(other)
|
|
78
|
+
if other.respond_to?(:zoned_date_time)
|
|
79
|
+
return zoned_date_time.to_instant.compare_to(other.zoned_date_time.to_instant)
|
|
80
|
+
end
|
|
81
|
+
|
|
78
82
|
case other
|
|
79
|
-
when
|
|
80
|
-
|
|
81
|
-
when TimeOfDay::TimeOfDay, TimeOfDay::TimeOfDayRangeElement
|
|
82
|
-
to_tod <=> other
|
|
83
|
-
when String
|
|
84
|
-
self <=> DateTime.parse(DATE_ONLY_REGEX =~ other ? "#{other}'T'00:00:00#{zone}" : other)
|
|
83
|
+
when TimeOfDay::TimeOfDay, TimeOfDay::TimeOfDayRangeElement then to_tod <=> other
|
|
84
|
+
when String then self <=> DateTime.parse(DATE_ONLY_REGEX =~ other ? "#{other}'T'00:00:00#{zone}" : other)
|
|
85
85
|
else
|
|
86
86
|
self <=> DateTime.from(other)
|
|
87
87
|
end
|
data/lib/openhab/log/logger.rb
CHANGED
|
@@ -22,9 +22,21 @@ module OpenHAB
|
|
|
22
22
|
#
|
|
23
23
|
# Regex for matching internal calls in a stack trace
|
|
24
24
|
#
|
|
25
|
-
INTERNAL_CALL_REGEX = %r{(openhab-scripting-.*/lib)|
|
|
25
|
+
INTERNAL_CALL_REGEX = %r{(openhab-scripting-.*/lib)|org[./]jruby}.freeze
|
|
26
26
|
private_constant :INTERNAL_CALL_REGEX
|
|
27
27
|
|
|
28
|
+
#
|
|
29
|
+
# Regex for matching internal calls in a java stack trace
|
|
30
|
+
#
|
|
31
|
+
EXCLUDED_JAVA_PACKAGES = /jdk\.internal\.reflect|java\.lang\.reflect|org\.openhab|java\.lang\.Thread\.run/.freeze
|
|
32
|
+
private_constant :EXCLUDED_JAVA_PACKAGES
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Regex for matching internal calls in a java stack trace
|
|
36
|
+
#
|
|
37
|
+
JAVA_INTERNAL_CALL_REGEX = Regexp.union(INTERNAL_CALL_REGEX, EXCLUDED_JAVA_PACKAGES).freeze
|
|
38
|
+
private_constant :JAVA_INTERNAL_CALL_REGEX
|
|
39
|
+
|
|
28
40
|
#
|
|
29
41
|
# Create a new logger
|
|
30
42
|
#
|
|
@@ -60,8 +72,13 @@ module OpenHAB
|
|
|
60
72
|
def clean_backtrace(error)
|
|
61
73
|
return error if debug_enabled?
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
if error.respond_to? :backtrace_locations
|
|
76
|
+
backtrace = error.backtrace_locations.map(&:to_s).reject { |line| INTERNAL_CALL_REGEX.match? line }
|
|
77
|
+
error.set_backtrace(backtrace)
|
|
78
|
+
elsif error.respond_to? :stack_trace
|
|
79
|
+
backtrace = error.stack_trace.reject { |line| JAVA_INTERNAL_CALL_REGEX.match? line.to_s }
|
|
80
|
+
error.set_stack_trace(backtrace)
|
|
81
|
+
end
|
|
65
82
|
error
|
|
66
83
|
end
|
|
67
84
|
|
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: 3.1
|
|
4
|
+
version: 3.4.1
|
|
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-04-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -25,19 +25,19 @@ dependencies:
|
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '2.2'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: marcel
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0
|
|
33
|
+
version: '1.0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0
|
|
40
|
+
version: '1.0'
|
|
41
41
|
description: JRuby Helper Libraries for OpenHAB Scripting
|
|
42
42
|
email:
|
|
43
43
|
- broconne@gmail.com
|