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
data/lib/openhab/core/dsl.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
require 'core/log'
|
5
|
-
require 'core/dsl/monkey_patch/events'
|
6
|
-
require 'core/dsl/monkey_patch/ruby/ruby'
|
7
|
-
require 'core/dsl/monkey_patch/items/items'
|
8
|
-
require 'core/dsl/monkey_patch/types/types'
|
9
|
-
require 'core/dsl/monkey_patch/actions/actions'
|
10
|
-
require 'core/dsl/rule/rule'
|
11
|
-
require 'core/dsl/actions'
|
12
|
-
require 'core/dsl/timers'
|
13
|
-
require 'core/dsl/group'
|
14
|
-
require 'core/dsl/things'
|
15
|
-
require 'core/dsl/items/items'
|
16
|
-
require 'core/dsl/items/number_item'
|
17
|
-
require 'core/dsl/time_of_day'
|
18
|
-
require 'core/dsl/gems'
|
19
|
-
require 'core/dsl/units'
|
20
|
-
require 'core/dsl/types/quantity'
|
21
|
-
require 'core/dsl/states'
|
22
|
-
require 'core/dsl/persistence'
|
23
|
-
|
24
|
-
module OpenHAB
|
25
|
-
#
|
26
|
-
# Holds core functions for OpenHAB Helper Library
|
27
|
-
#
|
28
|
-
module Core
|
29
|
-
#
|
30
|
-
# Module to be extended to access the OpenHAB Ruby DSL
|
31
|
-
#
|
32
|
-
module DSL
|
33
|
-
# Extend the calling module/class with the DSL
|
34
|
-
# rubocop: disable Metrics/MethodLength
|
35
|
-
def self.extended(base)
|
36
|
-
base.send :include, OpenHAB::Core::DSL::Rule
|
37
|
-
base.send :include, OpenHAB::Core::DSL::Items
|
38
|
-
base.send :include, OpenHAB::Core::DSL::Types
|
39
|
-
base.send :include, OpenHAB::Core::DSL::Groups
|
40
|
-
base.send :include, OpenHAB::Core::DSL::Units
|
41
|
-
base.send :include, OpenHAB::Core::DSL::Actions
|
42
|
-
base.send :include, OpenHAB::Core::DSL::Timers
|
43
|
-
base.send :include, OpenHAB::Core::DSL::States
|
44
|
-
base.send :include, OpenHAB::Core::DSL::Tod
|
45
|
-
base.send :include, OpenHAB::Core::DSL::Persistence
|
46
|
-
base.send :include, Things
|
47
|
-
end
|
48
|
-
# rubocop: enable Metrics/MethodLength
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
require 'openhab/osgi'
|
5
|
-
|
6
|
-
module OpenHAB
|
7
|
-
module Core
|
8
|
-
module DSL
|
9
|
-
#
|
10
|
-
# Module to import and steramlime access to OpenHAB actions
|
11
|
-
#
|
12
|
-
module Actions
|
13
|
-
java_import org.openhab.core.library.types.PercentType
|
14
|
-
include Logging
|
15
|
-
|
16
|
-
OpenHAB::OSGI.services('org.openhab.core.model.script.engine.action.ActionService')&.each do |service|
|
17
|
-
java_import service.actionClass.to_s
|
18
|
-
logger.trace("Loaded ACTION: #{service.actionClass}")
|
19
|
-
end
|
20
|
-
# Import common actions
|
21
|
-
%w[Exec HTTP Ping].each { |action| java_import "org.openhab.core.model.script.actions.#{action}" }
|
22
|
-
|
23
|
-
#
|
24
|
-
# Return an OpenHAB Action object for the given scope and thing
|
25
|
-
#
|
26
|
-
# @param scope [String] The action scope
|
27
|
-
# @param thing_uid [String] Thing UID
|
28
|
-
#
|
29
|
-
# @return [Object] OpenHAB action
|
30
|
-
#
|
31
|
-
def actions(scope, thing_uid)
|
32
|
-
# rubocop: disable Style/GlobalVars
|
33
|
-
$actions.get(scope, thing_uid)
|
34
|
-
# rubocop: enable Style/GlobalVars
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# Gets the list of action objects associated with a specific ThingUID
|
39
|
-
#
|
40
|
-
# @param [Java::org::openhab::core::thing::ThingUID] thing_uid to get associated actions for
|
41
|
-
#
|
42
|
-
# @return [Array] of action objects associated with thing_uid, may be empty
|
43
|
-
#
|
44
|
-
def actions_for_thing(thing_uid)
|
45
|
-
thing_uid = thing_uid.to_s
|
46
|
-
# rubocop: disable Style/GlobalVars
|
47
|
-
action_keys = $actions.action_keys
|
48
|
-
# rubocop: enable Style/GlobalVars
|
49
|
-
logger.trace("Registered actions: '#{action_keys}' for thing '#{thing_uid}'")
|
50
|
-
action_keys.map { |action_key| action_key.split('-', 2) }
|
51
|
-
.select { |action_pair| action_pair.last == thing_uid }
|
52
|
-
.map(&:first)
|
53
|
-
.map { |scope| actions(scope, thing_uid) }
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# Send notification to an email or broadcast
|
58
|
-
#
|
59
|
-
# @param msg [String] The notification message to send
|
60
|
-
# @param email [String] The email address to send to. If nil, the message will be broadcasted
|
61
|
-
#
|
62
|
-
# @return [void]
|
63
|
-
#
|
64
|
-
def notify(msg, email: nil)
|
65
|
-
unless defined? NotificationAction
|
66
|
-
raise NoMethodError, 'NotificationAction is not available. Please install the OpenHAB cloud addon'
|
67
|
-
end
|
68
|
-
|
69
|
-
if email
|
70
|
-
NotificationAction.sendNotification email, msg
|
71
|
-
else
|
72
|
-
NotificationAction.sendBroadcastNotification msg
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Say text via OpenHAB Text-To-Speech service, Voice.say()
|
78
|
-
#
|
79
|
-
# @param text [String] The text to say
|
80
|
-
# @param voice [String] Specify a particular voice to use
|
81
|
-
# @param sink [String] Specify a particular sink to output the speech
|
82
|
-
# @param volume [PercentType] Specify the volume for the speech
|
83
|
-
#
|
84
|
-
# @return [void]
|
85
|
-
#
|
86
|
-
def say(text, voice: nil, sink: nil, volume: nil)
|
87
|
-
volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
|
88
|
-
Voice.say text, voice, sink, volume
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# Play an audio file via OpenHAB sound service, Audio.playSound()
|
93
|
-
#
|
94
|
-
# @param filename [String] The sound file to play
|
95
|
-
# @param sink [String] Specify a particular sink to output the speech
|
96
|
-
# @param volume [PercentType] Specify the volume for the speech
|
97
|
-
#
|
98
|
-
# @return [void]
|
99
|
-
#
|
100
|
-
def play_sound(filename, sink: nil, volume: nil)
|
101
|
-
volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
|
102
|
-
Audio.playSound sink, filename, volume
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require 'java'
|
5
|
-
require 'set'
|
6
|
-
require 'core/dsl/group'
|
7
|
-
require 'core/log'
|
8
|
-
require 'core/dsl/items/number_item'
|
9
|
-
require 'core/dsl/items/string_item'
|
10
|
-
|
11
|
-
# Automation lookup and injection of OpenHab entities
|
12
|
-
java_import org.openhab.core.items.GroupItem
|
13
|
-
|
14
|
-
#
|
15
|
-
# Implements const_missing to return OpenHAB items or things if mapping to missing name if they exist
|
16
|
-
#
|
17
|
-
# @param [String] name Capital string that was not set as a constant and to be looked up
|
18
|
-
#
|
19
|
-
# @return [Object] OpenHAB Item or Thing if their name exist in OpenHAB item and thing regestries
|
20
|
-
#
|
21
|
-
def Object.const_missing(name)
|
22
|
-
EntityLookup.lookup_item(name) || EntityLookup.lookup_thing(name) || super
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Manages access to OpenHAB entities
|
27
|
-
#
|
28
|
-
module EntityLookup
|
29
|
-
include Logging
|
30
|
-
|
31
|
-
#
|
32
|
-
# Decorate items with Ruby wrappers
|
33
|
-
#
|
34
|
-
# @param [Array] items Array of items to decorate
|
35
|
-
#
|
36
|
-
# @return [Array] Array of decorated items
|
37
|
-
#
|
38
|
-
def self.decorate_items(*items)
|
39
|
-
items.flatten.map { |item| decorate_item(item) }
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Decorate item with Ruby wrappers
|
44
|
-
#
|
45
|
-
# @param [Object] item the item object to decorate
|
46
|
-
#
|
47
|
-
# @return [Object] the ruby wrapper for the item
|
48
|
-
#
|
49
|
-
def self.decorate_item(item)
|
50
|
-
case item
|
51
|
-
when GroupItem
|
52
|
-
decorate_group(item)
|
53
|
-
when Java::Org.openhab.core.library.items::NumberItem
|
54
|
-
OpenHAB::Core::DSL::Items::NumberItem.new(item)
|
55
|
-
when Java::Org.openhab.core.library.items::StringItem
|
56
|
-
OpenHAB::Core::DSL::Items::StringItem.new(item)
|
57
|
-
else
|
58
|
-
item
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Looks up a Thing in the OpenHAB registry replacing '_' with ':'
|
64
|
-
#
|
65
|
-
# @param [String] name of Thing to lookup in Thing registry
|
66
|
-
#
|
67
|
-
# @return [Thing] if found, nil otherwise
|
68
|
-
#
|
69
|
-
def self.lookup_thing(name)
|
70
|
-
logger.trace("Looking up thing(#{name})")
|
71
|
-
# Convert from : syntax to underscore
|
72
|
-
name = name.to_s if name.is_a? Symbol
|
73
|
-
|
74
|
-
# Thing UIDs have at least 3 segements
|
75
|
-
return if name.count('_') < 3
|
76
|
-
|
77
|
-
name = name.gsub('_', ':')
|
78
|
-
# rubocop: disable Style/GlobalVars
|
79
|
-
$things.get(Java::OrgOpenhabCoreThing::ThingUID.new(name))
|
80
|
-
# rubocop: enable Style/GlobalVars
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Lookup OpenHAB items in item registry
|
85
|
-
#
|
86
|
-
# @param [String] name of item to lookup
|
87
|
-
#
|
88
|
-
# @return [Item] OpenHAB item if registry contains a matching item, nil othewise
|
89
|
-
#
|
90
|
-
def self.lookup_item(name)
|
91
|
-
logger.trace("Looking up item(#{name})")
|
92
|
-
name = name.to_s if name.is_a? Symbol
|
93
|
-
# rubocop: disable Style/GlobalVars
|
94
|
-
item = $ir.get(name)
|
95
|
-
# rubocop: enable Style/GlobalVars
|
96
|
-
EntityLookup.decorate_item(item)
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# Automatically looks up OpenHAB items and things in appropriate registries
|
101
|
-
#
|
102
|
-
# @param [method] method Name of item to lookup
|
103
|
-
# @param [<Type>] args method arguments
|
104
|
-
# @param [<Type>] block supplied to missing method
|
105
|
-
#
|
106
|
-
# @return [Object] Item or Thing if found in registry
|
107
|
-
#
|
108
|
-
def method_missing(method, *args, &block)
|
109
|
-
return if method.to_s == 'scriptLoaded'
|
110
|
-
return if method.to_s == 'scriptUnloaded'
|
111
|
-
|
112
|
-
logger.trace("method missing, performing OpenHab Lookup for: #{method}")
|
113
|
-
EntityLookup.lookup_item(method) || EntityLookup.lookup_thing(method) || super
|
114
|
-
end
|
115
|
-
|
116
|
-
#
|
117
|
-
# Checks if this method responds to the missing method
|
118
|
-
#
|
119
|
-
# @param [String] method_name Name of the method to check
|
120
|
-
# @param [Boolean] _include_private boolean if private methods should be checked
|
121
|
-
#
|
122
|
-
# @return [Boolean] true if this object will respond to the supplied method, false otherwise
|
123
|
-
#
|
124
|
-
def respond_to_missing?(method_name, _include_private = false)
|
125
|
-
logger.trace("Checking if OpenHAB entites exist for #{method_name}")
|
126
|
-
method_name = method_name.to_s if method_name.is_a? Symbol
|
127
|
-
|
128
|
-
method_name == 'scriptLoaded' ||
|
129
|
-
method_name == 'scriptUnloaded' ||
|
130
|
-
EntityLookup.lookup_item(method_name) ||
|
131
|
-
EntityLookup.lookup_thing(method_name) ||
|
132
|
-
super
|
133
|
-
end
|
134
|
-
|
135
|
-
#
|
136
|
-
# Decorate a group from an item base
|
137
|
-
#
|
138
|
-
# @param [OpenHAB item] item item to convert to a group item
|
139
|
-
#
|
140
|
-
# @return [OpenHAB::Core::DSL::Groups::Group] Group created from supplied item
|
141
|
-
#
|
142
|
-
def self.decorate_group(item)
|
143
|
-
group = OpenHAB::Core::DSL::Groups::Group.new(Set.new(EntityLookup.decorate_items(item.all_members.to_a)))
|
144
|
-
group.group = item
|
145
|
-
group
|
146
|
-
end
|
147
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'delegate'
|
4
|
-
require 'forwardable'
|
5
|
-
require 'openhab/core/dsl/entities'
|
6
|
-
|
7
|
-
module OpenHAB
|
8
|
-
module Core
|
9
|
-
module DSL
|
10
|
-
#
|
11
|
-
# Provides access to OpenHAB Groups
|
12
|
-
#
|
13
|
-
module Groups
|
14
|
-
#
|
15
|
-
# Indicator struct interpreted by rules to trigger based on items contained in a group
|
16
|
-
#
|
17
|
-
GroupItems = Struct.new(:group, keyword_init: true)
|
18
|
-
|
19
|
-
#
|
20
|
-
# Provide access to groups as a set
|
21
|
-
#
|
22
|
-
class Groups < SimpleDelegator
|
23
|
-
#
|
24
|
-
# Get a OpenHAB Group by name
|
25
|
-
# @param [String] name of the group to retrieve
|
26
|
-
#
|
27
|
-
# @return [Set] of OpenHAB Groups
|
28
|
-
#
|
29
|
-
def[](name)
|
30
|
-
group = EntityLookup.lookup_item(name)
|
31
|
-
group.is_a?(Group) ? group : nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Retreive all OpenHAB groups
|
37
|
-
#
|
38
|
-
# @return [Set] of OpenHAB Groups
|
39
|
-
#
|
40
|
-
def groups
|
41
|
-
# rubocop: disable Style/GlobalVars
|
42
|
-
Groups.new(EntityLookup.decorate_items($ir.items.select { |item| item.is_a? GroupItem }))
|
43
|
-
# rubocop: enable Style/GlobalVars
|
44
|
-
end
|
45
|
-
|
46
|
-
# Group class that provides access to OpenHAB group object and delegates other methods to
|
47
|
-
# a set of group items
|
48
|
-
class Group < SimpleDelegator
|
49
|
-
extend Forwardable
|
50
|
-
|
51
|
-
java_import org.openhab.core.items.GroupItem
|
52
|
-
|
53
|
-
# @return [org.openhab.core.items.GroupItem] OpenHAB Java Group Item
|
54
|
-
attr_accessor :group
|
55
|
-
|
56
|
-
# @!macro [attach] def_delegators
|
57
|
-
# @!method $2
|
58
|
-
# Forwards to org.openhab.core.items.GroupItem
|
59
|
-
# @see org::openhab::core::items::GroupItem
|
60
|
-
def_delegator :@group, :name
|
61
|
-
def_delegator :@group, :label
|
62
|
-
|
63
|
-
#
|
64
|
-
# Gets members of this group that are themselves a group
|
65
|
-
#
|
66
|
-
# @return [Set] Set of members that are of type group
|
67
|
-
#
|
68
|
-
def groups
|
69
|
-
group.members.grep(org.openhab.core.items.GroupItem)
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
# Wraps the group in a struct, this method is intended to be called
|
74
|
-
# as an indicator to the rule method that the user wishes to trigger
|
75
|
-
# based on changes to group items
|
76
|
-
#
|
77
|
-
# @return [GroupItems] Indicator struct used by rules engine to trigger based on item changes
|
78
|
-
#
|
79
|
-
def items
|
80
|
-
GroupItems.new(group: group)
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# @return [String] List of groups seperated by commas
|
85
|
-
#
|
86
|
-
def to_s
|
87
|
-
"[#{map(&:to_s).join(',')}]"
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Get an ID for the group, using the label if set, otherwise group name
|
92
|
-
#
|
93
|
-
# @return [String] label if set otherwise name
|
94
|
-
#
|
95
|
-
def id
|
96
|
-
label || name
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
require 'openhab/core/dsl/entities'
|
5
|
-
|
6
|
-
module OpenHAB
|
7
|
-
module Core
|
8
|
-
module DSL
|
9
|
-
#
|
10
|
-
# Manages OpenHAB items
|
11
|
-
#
|
12
|
-
module Items
|
13
|
-
#
|
14
|
-
# Delegates to underlying set of all OpenHAB Items, provides convenience methods
|
15
|
-
#
|
16
|
-
class Items < SimpleDelegator
|
17
|
-
# Fetches the named item from the the ItemRegistry
|
18
|
-
# @param [String] name
|
19
|
-
# @return Item from registry, nil if item missing or requested item is a Group Type
|
20
|
-
def[](name)
|
21
|
-
# rubocop: disable Style/GlobalVars
|
22
|
-
item = $ir.getItem(name)
|
23
|
-
# rubocop: enable Style/GlobalVars
|
24
|
-
item.is_a?(GroupItem) ? nil : EntityLookup.decorate_item(item)
|
25
|
-
rescue Java::OrgOpenhabCoreItems::ItemNotFoundException
|
26
|
-
nil
|
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
|
-
# rubocop: disable Style/GlobalVars
|
34
|
-
!$ir.getItems(name).empty?
|
35
|
-
# rubocop: enable Style/GlobalVars
|
36
|
-
end
|
37
|
-
alias key? include?
|
38
|
-
end
|
39
|
-
|
40
|
-
java_import org.openhab.core.items.GroupItem
|
41
|
-
# Fetches all non-group items from the item registry
|
42
|
-
# @return [OpenHAB::Core::DSL::Items::Items]
|
43
|
-
def items
|
44
|
-
# rubocop: disable Style/GlobalVars
|
45
|
-
Items.new(EntityLookup.decorate_items($ir.items.reject { |item| item.is_a? GroupItem }))
|
46
|
-
# rubocop: enable Style/GlobalVars
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|