openhab-scripting 3.9.4 → 4.1.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/group_item.rb +22 -3
- data/lib/openhab/dsl/items/item_command.rb +8 -4
- data/lib/openhab/dsl/items/items.rb +28 -8
- 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/decimal_type.rb +5 -0
- 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/rules/triggers/command.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/trigger.rb +6 -2
- data/lib/openhab/dsl/rules/triggers/updated.rb +1 -1
- data/lib/openhab/dsl/things.rb +32 -9
- 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: 2210f9eb88b639bd2ca594cce368ec87ee7746595f7b2f9c04e7bd1ebdf10fc3
|
4
|
+
data.tar.gz: 9dae7f3f53574ba089c37c52e35e110c596a09deb3005ced5a267d18d64b1f3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be659fbac0f529674ffb4a38944e1f2365fa82a08bbc832edb0ad3a5f074ec683454980050758ba6810b52abaf42d8ab8f442d73276de4fe38d51a8984e7b61a
|
7
|
+
data.tar.gz: a58d4df593b831c3daf979b2d0094691e22d2be849a375c9bf7c0a30d78e9e4d71d36adfa85d918debd1a8e948ec9b6d7b57e933f9eb791cf9d769ee5ce02193
|
@@ -13,7 +13,9 @@ module OpenHAB
|
|
13
13
|
#
|
14
14
|
# Class for indicating to triggers that a group trigger should be used
|
15
15
|
#
|
16
|
-
class GroupMembers
|
16
|
+
class GroupMembers
|
17
|
+
include Enumerable
|
18
|
+
|
17
19
|
attr_reader :group
|
18
20
|
|
19
21
|
#
|
@@ -23,8 +25,24 @@ module OpenHAB
|
|
23
25
|
#
|
24
26
|
def initialize(group_item)
|
25
27
|
@group = group_item
|
26
|
-
super(OpenHAB::Core::EntityLookup.decorate_items(@group.members.to_a))
|
27
28
|
end
|
29
|
+
|
30
|
+
# Calls the given block once for each group member, passing that
|
31
|
+
# item as a parameter. Returns self.
|
32
|
+
#
|
33
|
+
# If no block is given, an Enumerator is returned.
|
34
|
+
def each(&block)
|
35
|
+
to_a.each(&block)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
# explicit conversion to array
|
40
|
+
# more efficient than letting Enumerable do it
|
41
|
+
def to_a
|
42
|
+
OpenHAB::Core::EntityLookup.decorate_items(group.members.to_a)
|
43
|
+
end
|
44
|
+
# implicitly convertible to array
|
45
|
+
alias to_ary to_a
|
28
46
|
end
|
29
47
|
|
30
48
|
#
|
@@ -68,12 +86,13 @@ module OpenHAB
|
|
68
86
|
def members
|
69
87
|
GroupMembers.new(@group_item)
|
70
88
|
end
|
89
|
+
alias items members
|
71
90
|
|
72
91
|
#
|
73
92
|
# Iterates through the direct members of the Group
|
74
93
|
#
|
75
94
|
def each(&block)
|
76
|
-
|
95
|
+
members.each(&block)
|
77
96
|
end
|
78
97
|
|
79
98
|
#
|
@@ -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
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'java'
|
4
4
|
require 'openhab/core/entity_lookup'
|
5
|
+
require 'singleton'
|
5
6
|
|
6
7
|
module OpenHAB
|
7
8
|
module DSL
|
@@ -12,11 +13,14 @@ module OpenHAB
|
|
12
13
|
#
|
13
14
|
# Delegates to underlying set of all OpenHAB Items, provides convenience methods
|
14
15
|
#
|
15
|
-
class Items
|
16
|
+
class Items
|
17
|
+
include Enumerable
|
18
|
+
include Singleton
|
19
|
+
|
16
20
|
# Fetches the named item from the the ItemRegistry
|
17
21
|
# @param [String] name
|
18
22
|
# @return Item from registry, nil if item missing or requested item is a Group Type
|
19
|
-
def[](name)
|
23
|
+
def [](name)
|
20
24
|
OpenHAB::Core::EntityLookup.lookup_item(name)
|
21
25
|
rescue Java::OrgOpenhabCoreItems::ItemNotFoundException
|
22
26
|
nil
|
@@ -26,19 +30,35 @@ module OpenHAB
|
|
26
30
|
# @param name [String] Item name to check
|
27
31
|
# @return [Boolean] true if the item exists, false otherwise
|
28
32
|
def include?(name)
|
29
|
-
# rubocop: disable Style/GlobalVars
|
30
|
-
!$ir.getItems(name).empty?
|
31
|
-
# rubocop: enable Style/GlobalVars
|
33
|
+
!$ir.getItems(name).empty? # rubocop: disable Style/GlobalVars
|
32
34
|
end
|
33
35
|
alias key? include?
|
36
|
+
|
37
|
+
# Calls the given block once for each Item, passing that Item as a
|
38
|
+
# parameter. Returns self.
|
39
|
+
#
|
40
|
+
# If no block is given, an Enumerator is returned.
|
41
|
+
def each(&block)
|
42
|
+
# ideally we would do this lazily, but until ruby 2.7
|
43
|
+
# there's no #eager method to convert back to a non-lazy
|
44
|
+
# enumerator
|
45
|
+
to_a.each(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# explicit conversion to array
|
49
|
+
# more efficient than letting Enumerable do it
|
50
|
+
def to_a
|
51
|
+
items = $ir.items.grep_v(Java::OrgOpenhabCoreItems::GroupItem) # rubocop:disable Style/GlobalVars
|
52
|
+
OpenHAB::Core::EntityLookup.decorate_items(items)
|
53
|
+
end
|
54
|
+
# implicitly convertible to array
|
55
|
+
alias to_ary to_a
|
34
56
|
end
|
35
57
|
|
36
58
|
# Fetches all non-group items from the item registry
|
37
59
|
# @return [OpenHAB::DSL::Items::Items]
|
38
60
|
def items
|
39
|
-
|
40
|
-
Items.new(OpenHAB::Core::EntityLookup.decorate_items($ir.items.grep_v(Java::OrgOpenhabCoreItems::GroupItem)))
|
41
|
-
# rubocop: enable Style/GlobalVars
|
61
|
+
Items.instance
|
42
62
|
end
|
43
63
|
end
|
44
64
|
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
|
@@ -22,7 +22,7 @@ module OpenHAB
|
|
22
22
|
#
|
23
23
|
#
|
24
24
|
def received_command(*items, command: nil, commands: nil)
|
25
|
-
separate_groups(items).
|
25
|
+
separate_groups(items).each do |item|
|
26
26
|
logger.trace("Creating received command trigger for item(#{item})"\
|
27
27
|
"command(#{command}) commands(#{commands})")
|
28
28
|
|
@@ -61,9 +61,13 @@ module OpenHAB
|
|
61
61
|
# @return [Array] A new flat array with any GroupMembers object left intact
|
62
62
|
#
|
63
63
|
def separate_groups(item_array)
|
64
|
-
|
64
|
+
# we want to support anything that can be flattened... i.e. responds to to_ary
|
65
|
+
# we want to be more lenient than only things that are currently Array,
|
66
|
+
# but Enumerable is too lenient because Array#flatten won't traverse interior
|
67
|
+
# Enumerables
|
68
|
+
return item_array unless item_array.find { |item| item.respond_to?(:to_ary) }
|
65
69
|
|
66
|
-
groups, items = item_array.partition { |item| item.is_a?
|
70
|
+
groups, items = item_array.partition { |item| item.is_a?(OpenHAB::DSL::Items::GroupItem::GroupMembers) }
|
67
71
|
groups + separate_groups(items.flatten(1))
|
68
72
|
end
|
69
73
|
|
@@ -20,7 +20,7 @@ module OpenHAB
|
|
20
20
|
# @return [Trigger] Trigger for updated entity
|
21
21
|
#
|
22
22
|
def updated(*items, to: nil)
|
23
|
-
separate_groups(items).
|
23
|
+
separate_groups(items).each do |item|
|
24
24
|
logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
|
25
25
|
[to].flatten.each do |to_state|
|
26
26
|
trigger, config = create_update_trigger(item, to_state)
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -4,6 +4,7 @@ require 'java'
|
|
4
4
|
require 'openhab/log/logger'
|
5
5
|
require 'openhab/dsl/actions'
|
6
6
|
require 'delegate'
|
7
|
+
require 'singleton'
|
7
8
|
|
8
9
|
module OpenHAB
|
9
10
|
module DSL
|
@@ -76,32 +77,54 @@ module OpenHAB
|
|
76
77
|
#
|
77
78
|
# Wraps all Things in a delegator to underlying set and provides lookup method
|
78
79
|
#
|
79
|
-
class Things
|
80
|
+
class Things
|
80
81
|
java_import org.openhab.core.thing.ThingUID
|
81
82
|
|
83
|
+
include Enumerable
|
84
|
+
include Singleton
|
85
|
+
|
82
86
|
# Gets a specific thing by name in the format binding_id:type_id:thing_id
|
83
87
|
# @return Thing specified by name or nil if name does not exist in thing registry
|
84
|
-
def[](uid)
|
88
|
+
def [](uid)
|
85
89
|
thing_uid = ThingUID.new(*uid.split(':'))
|
86
|
-
# rubocop: disable Style/GlobalVars
|
87
|
-
thing = $things.get(thing_uid)
|
88
|
-
# rubocop: enable Style/GlobalVars
|
90
|
+
thing = $things.get(thing_uid) # rubocop: disable Style/GlobalVars
|
89
91
|
return unless thing
|
90
92
|
|
91
93
|
logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
|
92
94
|
Thing.new(thing)
|
93
95
|
end
|
96
|
+
|
97
|
+
alias include? []
|
98
|
+
alias key? []
|
99
|
+
|
100
|
+
# Calls the given block once for each Thing, passing that Thing as a
|
101
|
+
# parameter. Returns self.
|
102
|
+
#
|
103
|
+
# If no block is given, an Enumerator is returned.
|
104
|
+
def each(&block)
|
105
|
+
# ideally we would do this lazily, but until ruby 2.7
|
106
|
+
# there's no #eager method to convert back to a non-lazy
|
107
|
+
# enumerator
|
108
|
+
to_a.each(&block)
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
# explicit conversion to array
|
113
|
+
# more efficient than letting Enumerable do it
|
114
|
+
def to_a
|
115
|
+
$things.getAll.map { |thing| Thing.new(thing) } # rubocop: disable Style/GlobalVars
|
116
|
+
end
|
117
|
+
# implicitly convertible to array
|
118
|
+
alias to_ary to_a
|
94
119
|
end
|
95
120
|
|
96
121
|
#
|
97
122
|
# Get all things known to OpenHAB
|
98
123
|
#
|
99
|
-
# @return [
|
124
|
+
# @return [Things] all Thing objects known to OpenHAB
|
100
125
|
#
|
101
126
|
def things
|
102
|
-
|
103
|
-
Things.new($things.getAll.map { |thing| Thing.new(thing) }.to_set)
|
104
|
-
# rubocop: enable Style/GlobalVars
|
127
|
+
Things.instance
|
105
128
|
end
|
106
129
|
end
|
107
130
|
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
|
+
version: 4.1.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-10-07 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
|