openhab-scripting 3.9.1 → 4.0.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/entity_lookup.rb +1 -1
- data/lib/openhab/dsl/items/group_item.rb +1 -0
- data/lib/openhab/dsl/items/item_command.rb +8 -4
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +19 -0
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +40 -1
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +39 -2
- data/lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/next_previous_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +23 -10
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +22 -6
- data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +45 -0
- data/lib/openhab/dsl/monkey_patch/types/play_pause_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/refresh_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/stop_move_type.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/types/types.rb +6 -0
- data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +20 -0
- data/lib/openhab/dsl/timers.rb +2 -2
- data/lib/openhab/dsl/types/datetime.rb +3 -3
- data/lib/openhab/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf75e647f468a653d6848739cf2552ba57b9d1b1d81f33eed2f3719315d28d11
|
|
4
|
+
data.tar.gz: 8f6403a4642e1edd1eb3047d438939b5d127c0fd0eca57c8989e9a72bf0bdb39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e0ea6a8962334965162c95ff2db82a3fcf0485c6b80fefd2ea0814d0883678052bd52306093ea70e2cb0aec9e3fb8df42fd9290f9b9b21ddfb71db11649f104
|
|
7
|
+
data.tar.gz: 4d492998dd50c6b25fd845df988d7ef418e5d2a8a66c339bf5fabf990cd6380d6a588ee6fc899d47d697564b78c88397a77d362a39da0a6d7f9d7ba3c99d4c71
|
|
@@ -129,7 +129,7 @@ module OpenHAB
|
|
|
129
129
|
# Thing UIDs have at least 3 segements
|
|
130
130
|
return if name.count('_') < 3
|
|
131
131
|
|
|
132
|
-
name = name.
|
|
132
|
+
name = name.tr('_', ':')
|
|
133
133
|
# rubocop: disable Style/GlobalVars
|
|
134
134
|
$things.get(Java::OrgOpenhabCoreThing::ThingUID.new(name))
|
|
135
135
|
# rubocop: enable Style/GlobalVars
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'java'
|
|
4
4
|
require 'openhab/log/logger'
|
|
5
|
+
require 'openhab/dsl/monkey_patch/events/item_command'
|
|
5
6
|
|
|
6
7
|
module OpenHAB
|
|
7
8
|
module DSL
|
|
@@ -28,7 +29,7 @@ module OpenHAB
|
|
|
28
29
|
command_enum.values.each do |command|
|
|
29
30
|
command_method = command.to_s.downcase
|
|
30
31
|
command_method = methods.transform_keys(&:to_sym).fetch(command_method.to_sym, command_method)
|
|
31
|
-
logger.trace("Creating command method (#{command_method}) for #{self
|
|
32
|
+
logger.trace("Creating command method (#{command_method}) for #{self}")
|
|
32
33
|
define_method(command_method) do
|
|
33
34
|
self.command(command)
|
|
34
35
|
end
|
|
@@ -54,7 +55,7 @@ module OpenHAB
|
|
|
54
55
|
command_enum.values.each do |command|
|
|
55
56
|
status_method = "#{command.to_s.downcase}?"
|
|
56
57
|
status_method = methods.transform_keys(&:to_sym).fetch(status_method.to_sym, status_method)
|
|
57
|
-
logger.trace("Creating status method (#{status_method}) for #{self
|
|
58
|
+
logger.trace("Creating status method (#{status_method}) for #{self}")
|
|
58
59
|
define_method(status_method) do
|
|
59
60
|
state? && state.as(command_enum) == command
|
|
60
61
|
end
|
|
@@ -70,7 +71,7 @@ module OpenHAB
|
|
|
70
71
|
# @param [Hash] optional hash in which if a generated method name mactches a key, the value of that key
|
|
71
72
|
# will be used as the method name instead, for example `:play? => :playing?`
|
|
72
73
|
#
|
|
73
|
-
def item_type(item_class, methods = {})
|
|
74
|
+
def item_type(item_class, methods = {}) # rubocop:disable Metrics/MethodLength
|
|
74
75
|
item_class.field_reader(:ACCEPTED_DATA_TYPES)
|
|
75
76
|
item_class.field_reader(:ACCEPTED_COMMAND_TYPES)
|
|
76
77
|
item_class.ACCEPTED_DATA_TYPES.select(&:is_enum)
|
|
@@ -78,7 +79,10 @@ module OpenHAB
|
|
|
78
79
|
.each { |type| item_state(type.ruby_class, methods) }
|
|
79
80
|
item_class.ACCEPTED_COMMAND_TYPES.select(&:is_enum)
|
|
80
81
|
.grep_v(UnDefType)
|
|
81
|
-
.each
|
|
82
|
+
.each do |type|
|
|
83
|
+
item_command(type.ruby_class, methods)
|
|
84
|
+
MonkeyPatch::Events::ItemCommandEvent.def_enum_predicates(type.ruby_class)
|
|
85
|
+
end
|
|
82
86
|
end
|
|
83
87
|
end
|
|
84
88
|
end
|
|
@@ -15,7 +15,26 @@ module OpenHAB
|
|
|
15
15
|
# Monkey patch with ruby style accesors
|
|
16
16
|
#
|
|
17
17
|
class ItemCommandEvent
|
|
18
|
+
include Log
|
|
19
|
+
|
|
18
20
|
alias command item_command
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# For every value in the supplied enumeration create a corresponding method mapped to the lowercase
|
|
24
|
+
# string representation of the enum value For example, an enum with values of STOP and START
|
|
25
|
+
# would create methods stop? and start? that check if the command is corresponding STOP and START type
|
|
26
|
+
#
|
|
27
|
+
# @param [Java::JavaLang::Enum] command_enum Enumeration to create commands for
|
|
28
|
+
#
|
|
29
|
+
def self.def_enum_predicates(command_enum)
|
|
30
|
+
command_enum.values.each do |command| # rubocop:disable Style/HashEachMethods : Java enum does not have each_value
|
|
31
|
+
command_method = "#{command.to_s.downcase}?"
|
|
32
|
+
logger.trace("Creating predicate method (#{command_method}) for #{self}")
|
|
33
|
+
define_method(command_method) do
|
|
34
|
+
self.command == command
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
19
38
|
end
|
|
20
39
|
end
|
|
21
40
|
end
|
|
@@ -10,12 +10,51 @@ module OpenHAB
|
|
|
10
10
|
#
|
|
11
11
|
module Events
|
|
12
12
|
java_import Java::OrgOpenhabCoreItemsEvents::ItemStateEvent
|
|
13
|
+
java_import Java::OrgOpenhabCoreTypes::UnDefType
|
|
14
|
+
|
|
15
|
+
# Helpers common to ItemStateEvent and ItemStateChangedEvent
|
|
16
|
+
module ItemStateUnDefTypeHelpers
|
|
17
|
+
#
|
|
18
|
+
# Check if the state == UNDEF
|
|
19
|
+
#
|
|
20
|
+
# @return [Boolean] True if the state is UNDEF, false otherwise
|
|
21
|
+
#
|
|
22
|
+
def undef?
|
|
23
|
+
item_state == UnDefType::UNDEF
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Check if the state == NULL
|
|
28
|
+
#
|
|
29
|
+
# @return [Boolean] True if the state is NULL, false otherwise
|
|
30
|
+
def null?
|
|
31
|
+
item_state == UnDefType::NULL
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Check if the state is defined (not UNDEF or NULL)
|
|
36
|
+
#
|
|
37
|
+
# @return [Boolean] True if state is not UNDEF or NULL
|
|
38
|
+
#
|
|
39
|
+
def state?
|
|
40
|
+
undef? == false && null? == false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#
|
|
44
|
+
# Get the item state
|
|
45
|
+
#
|
|
46
|
+
# @return [State] OpenHAB state if state is not UNDEF or NULL, nil otherwise
|
|
47
|
+
#
|
|
48
|
+
def state
|
|
49
|
+
item_state if state?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
13
52
|
|
|
14
53
|
#
|
|
15
54
|
# MonkeyPatch with ruby style accessors
|
|
16
55
|
#
|
|
17
56
|
class ItemStateEvent
|
|
18
|
-
|
|
57
|
+
include ItemStateUnDefTypeHelpers
|
|
19
58
|
end
|
|
20
59
|
end
|
|
21
60
|
end
|
|
@@ -10,13 +10,50 @@ module OpenHAB
|
|
|
10
10
|
#
|
|
11
11
|
module Events
|
|
12
12
|
java_import Java::OrgOpenhabCoreItemsEvents::ItemStateChangedEvent
|
|
13
|
+
java_import Java::OrgOpenhabCoreTypes::UnDefType
|
|
13
14
|
|
|
14
15
|
#
|
|
15
16
|
# MonkeyPatch with ruby style accessors
|
|
16
17
|
#
|
|
17
18
|
class ItemStateChangedEvent
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
include ItemStateUnDefTypeHelpers
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Check if state was == UNDEF
|
|
23
|
+
#
|
|
24
|
+
# @return [Boolean] True if the state is UNDEF, false otherwise
|
|
25
|
+
#
|
|
26
|
+
def was_undef?
|
|
27
|
+
old_item_state == UnDefType::UNDEF
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Check if state was == NULL
|
|
32
|
+
#
|
|
33
|
+
# @return [Boolean] True if the state is NULL, false otherwise
|
|
34
|
+
def was_null?
|
|
35
|
+
old_item_state == UnDefType::NULL
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Check if state was defined (not UNDEF or NULL)
|
|
40
|
+
#
|
|
41
|
+
# @return [Boolean] True if state is not UNDEF or NULL
|
|
42
|
+
#
|
|
43
|
+
def was?
|
|
44
|
+
was_undef? == false && was_null? == false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#
|
|
48
|
+
# Get the previous item state
|
|
49
|
+
#
|
|
50
|
+
# @return [State] OpenHAB state if state was not UNDEF or NULL, nil otherwise
|
|
51
|
+
#
|
|
52
|
+
def was
|
|
53
|
+
old_item_state if was?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
alias last was
|
|
20
57
|
end
|
|
21
58
|
end
|
|
22
59
|
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::IncreaseDecreaseType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class IncreaseDecreaseType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::NextPreviousType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class NextPreviousType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -33,16 +33,9 @@ module OpenHAB
|
|
|
33
33
|
# nil if object cannot be compared
|
|
34
34
|
#
|
|
35
35
|
def ===(other)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
other.on? if other.respond_to? :on?
|
|
40
|
-
elsif self == OFF
|
|
41
|
-
other.off? if other.respond_to?('off?')
|
|
42
|
-
else
|
|
43
|
-
false
|
|
44
|
-
end
|
|
45
|
-
# rubocop:enable Style/CaseLikeIf
|
|
36
|
+
(on? && other.respond_to?(:on?) && other.on?) ||
|
|
37
|
+
(off? && other.respond_to?(:off?) && other.off?) ||
|
|
38
|
+
super
|
|
46
39
|
end
|
|
47
40
|
|
|
48
41
|
#
|
|
@@ -59,6 +52,26 @@ module OpenHAB
|
|
|
59
52
|
super
|
|
60
53
|
end
|
|
61
54
|
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Check if the state is ON
|
|
58
|
+
#
|
|
59
|
+
# @return [Boolean] true if ON, false otherwise
|
|
60
|
+
#
|
|
61
|
+
def on?
|
|
62
|
+
self == ON
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Check if the state is OFF
|
|
67
|
+
#
|
|
68
|
+
# @return [Boolean] true if OFF, false otherwise
|
|
69
|
+
#
|
|
70
|
+
def off?
|
|
71
|
+
self == OFF
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
alias inspect to_s
|
|
62
75
|
end
|
|
63
76
|
end
|
|
64
77
|
end
|
|
@@ -25,13 +25,9 @@ module OpenHAB
|
|
|
25
25
|
# @return [Boolean] True if the other object is a ContactItem and has the same state
|
|
26
26
|
#
|
|
27
27
|
def ===(other)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
elsif other.is_a? OpenClosedType
|
|
31
|
-
self == other
|
|
32
|
-
else
|
|
28
|
+
(open? && other.respond_to?(:open?) && other.open?) ||
|
|
29
|
+
(closed? && other.respond_to?(:closed?) && other.closed?) ||
|
|
33
30
|
super
|
|
34
|
-
end
|
|
35
31
|
end
|
|
36
32
|
|
|
37
33
|
#
|
|
@@ -48,6 +44,26 @@ module OpenHAB
|
|
|
48
44
|
super
|
|
49
45
|
end
|
|
50
46
|
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
# Check if the state is OPEN
|
|
50
|
+
#
|
|
51
|
+
# @return [Boolean] true if OPEN, false otherwise
|
|
52
|
+
#
|
|
53
|
+
def open?
|
|
54
|
+
self == OPEN
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
# Check if the state is CLOSED
|
|
59
|
+
#
|
|
60
|
+
# @return [Boolean] true if CLOSED, false otherwise
|
|
61
|
+
#
|
|
62
|
+
def closed?
|
|
63
|
+
self == CLOSED
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
alias inspect to_s
|
|
51
67
|
end
|
|
52
68
|
end
|
|
53
69
|
end
|
|
@@ -25,6 +25,51 @@ module OpenHAB
|
|
|
25
25
|
super
|
|
26
26
|
end
|
|
27
27
|
# rubocop:enable Lint/UselessMethodDefinition
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Provide details about PercentType object
|
|
31
|
+
#
|
|
32
|
+
# @return [String] Representing details about the PercentType object
|
|
33
|
+
#
|
|
34
|
+
def inspect
|
|
35
|
+
"#{to_string}%"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Check if the state is ON
|
|
40
|
+
#
|
|
41
|
+
# @return [Boolean] true if ON, false otherwise
|
|
42
|
+
#
|
|
43
|
+
def on?
|
|
44
|
+
as(OnOffType).on?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#
|
|
48
|
+
# Check if the state is OFF
|
|
49
|
+
#
|
|
50
|
+
# @return [Boolean] true if OFF, false otherwise
|
|
51
|
+
#
|
|
52
|
+
def off?
|
|
53
|
+
as(OnOffType).off?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Check if the state is UP
|
|
58
|
+
#
|
|
59
|
+
# @return [Boolean] true if UP, false otherwise
|
|
60
|
+
#
|
|
61
|
+
def up?
|
|
62
|
+
!!as(UpDownType)&.up?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Check if the state is DOWN
|
|
67
|
+
#
|
|
68
|
+
# @return [Boolean] true if DOWN, false otherwise
|
|
69
|
+
#
|
|
70
|
+
def down?
|
|
71
|
+
!!as(UpDownType)&.down?
|
|
72
|
+
end
|
|
28
73
|
end
|
|
29
74
|
end
|
|
30
75
|
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::PlayPauseType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class PlayPauseType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreTypes::RefreshType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class RefreshType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::RewindFastforwardType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class RewindFastforwardType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
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 types
|
|
10
|
+
#
|
|
11
|
+
module Types
|
|
12
|
+
java_import Java::OrgOpenhabCoreLibraryTypes::StopMoveType
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Monkey patch for DSL use
|
|
16
|
+
#
|
|
17
|
+
class StopMoveType
|
|
18
|
+
alias inspect to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
require 'openhab/dsl/monkey_patch/types/open_closed_type'
|
|
5
5
|
require 'openhab/dsl/monkey_patch/types/on_off_type'
|
|
6
6
|
require 'openhab/dsl/monkey_patch/types/decimal_type'
|
|
7
|
+
require 'openhab/dsl/monkey_patch/types/increase_decrease_type'
|
|
8
|
+
require 'openhab/dsl/monkey_patch/types/next_previous_type'
|
|
7
9
|
require 'openhab/dsl/monkey_patch/types/percent_type'
|
|
10
|
+
require 'openhab/dsl/monkey_patch/types/play_pause_type'
|
|
8
11
|
require 'openhab/dsl/monkey_patch/types/quantity_type'
|
|
12
|
+
require 'openhab/dsl/monkey_patch/types/refresh_type'
|
|
13
|
+
require 'openhab/dsl/monkey_patch/types/rewind_fastforward_type'
|
|
14
|
+
require 'openhab/dsl/monkey_patch/types/stop_move_type'
|
|
9
15
|
require 'openhab/dsl/monkey_patch/types/up_down_type'
|
|
@@ -45,6 +45,26 @@ module OpenHAB
|
|
|
45
45
|
super
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# Check if the state is UP
|
|
51
|
+
#
|
|
52
|
+
# @return [Boolean] true if UP, false otherwise
|
|
53
|
+
#
|
|
54
|
+
def up?
|
|
55
|
+
self == UP
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# Check if the state is DOWN
|
|
60
|
+
#
|
|
61
|
+
# @return [Boolean] true if DOWN, false otherwise
|
|
62
|
+
#
|
|
63
|
+
def down?
|
|
64
|
+
self == DOWN
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
alias inspect to_s
|
|
48
68
|
end
|
|
49
69
|
end
|
|
50
70
|
end
|
data/lib/openhab/dsl/timers.rb
CHANGED
|
@@ -31,14 +31,14 @@ module OpenHAB
|
|
|
31
31
|
# @param [Duration] duration Duration until timer should fire
|
|
32
32
|
# @param [Block] block Block to execute when timer fires
|
|
33
33
|
#
|
|
34
|
-
def initialize(duration
|
|
34
|
+
def initialize(duration:)
|
|
35
35
|
@duration = duration
|
|
36
36
|
|
|
37
37
|
# A semaphore is used to prevent a race condition in which calling the block from the timer thread
|
|
38
38
|
# occurs before the @timer variable can be set resulting in @timer being nil
|
|
39
39
|
semaphore = Mutex.new
|
|
40
40
|
|
|
41
|
-
timer_block = proc { semaphore.synchronize {
|
|
41
|
+
timer_block = proc { semaphore.synchronize { yield(self) } }
|
|
42
42
|
|
|
43
43
|
semaphore.synchronize do
|
|
44
44
|
@timer = ScriptExecution.createTimer(
|
|
@@ -81,7 +81,7 @@ module OpenHAB
|
|
|
81
81
|
|
|
82
82
|
case other
|
|
83
83
|
when TimeOfDay::TimeOfDay, TimeOfDay::TimeOfDayRangeElement then to_tod <=> other
|
|
84
|
-
when String then self <=> DateTime.parse(DATE_ONLY_REGEX
|
|
84
|
+
when String then self <=> DateTime.parse(DATE_ONLY_REGEX.match?(other) ? "#{other}'T'00:00:00#{zone}" : other)
|
|
85
85
|
else
|
|
86
86
|
self <=> DateTime.from(other)
|
|
87
87
|
end
|
|
@@ -120,7 +120,7 @@ module OpenHAB
|
|
|
120
120
|
when Numeric then DateTime.from(to_time - other)
|
|
121
121
|
when String
|
|
122
122
|
dt = DateTime.parse(other)
|
|
123
|
-
TIME_ONLY_REGEX
|
|
123
|
+
TIME_ONLY_REGEX.match?(other) ? self - dt.to_f : time_diff(dt)
|
|
124
124
|
when Duration then DateTime.new(zoned_date_time.minus(other))
|
|
125
125
|
when Time, DateTime, DateTimeType, DateTimeItem then time_diff(other)
|
|
126
126
|
end
|
|
@@ -298,7 +298,7 @@ module OpenHAB
|
|
|
298
298
|
# @return [Java::org::openhab::core::library::types::DateTimeType] Object representing the same time
|
|
299
299
|
#
|
|
300
300
|
def self.parse(time_string)
|
|
301
|
-
time_string += 'Z' if TIME_ONLY_REGEX
|
|
301
|
+
time_string += 'Z' if TIME_ONLY_REGEX.match?(time_string)
|
|
302
302
|
DateTime.new(DateTimeType.new(time_string))
|
|
303
303
|
rescue Java::JavaLang::StringIndexOutOfBoundsException, Java::JavaLang::IllegalArgumentException
|
|
304
304
|
# Try ruby's Time.parse if OpenHAB's DateTimeType parser fails
|
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
|
+
version: 4.0.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-10-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -84,10 +84,16 @@ files:
|
|
|
84
84
|
- lib/openhab/dsl/monkey_patch/ruby/string.rb
|
|
85
85
|
- lib/openhab/dsl/monkey_patch/ruby/time.rb
|
|
86
86
|
- lib/openhab/dsl/monkey_patch/types/decimal_type.rb
|
|
87
|
+
- lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb
|
|
88
|
+
- lib/openhab/dsl/monkey_patch/types/next_previous_type.rb
|
|
87
89
|
- lib/openhab/dsl/monkey_patch/types/on_off_type.rb
|
|
88
90
|
- lib/openhab/dsl/monkey_patch/types/open_closed_type.rb
|
|
89
91
|
- lib/openhab/dsl/monkey_patch/types/percent_type.rb
|
|
92
|
+
- lib/openhab/dsl/monkey_patch/types/play_pause_type.rb
|
|
90
93
|
- lib/openhab/dsl/monkey_patch/types/quantity_type.rb
|
|
94
|
+
- lib/openhab/dsl/monkey_patch/types/refresh_type.rb
|
|
95
|
+
- lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb
|
|
96
|
+
- lib/openhab/dsl/monkey_patch/types/stop_move_type.rb
|
|
91
97
|
- lib/openhab/dsl/monkey_patch/types/types.rb
|
|
92
98
|
- lib/openhab/dsl/monkey_patch/types/up_down_type.rb
|
|
93
99
|
- lib/openhab/dsl/persistence.rb
|