openhab-jrubyscripting 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/openhab/core/actions.rb +163 -0
- data/lib/openhab/core/entity_lookup.rb +144 -0
- data/lib/openhab/core/events/abstract_event.rb +17 -0
- data/lib/openhab/core/events/item_channel_link.rb +36 -0
- data/lib/openhab/core/events/item_command_event.rb +78 -0
- data/lib/openhab/core/events/item_event.rb +22 -0
- data/lib/openhab/core/events/item_state_changed_event.rb +52 -0
- data/lib/openhab/core/events/item_state_event.rb +51 -0
- data/lib/openhab/core/events/thing.rb +29 -0
- data/lib/openhab/core/events/thing_status_info_event.rb +53 -0
- data/lib/openhab/core/events.rb +10 -0
- data/lib/openhab/core/items/accepted_data_types.rb +29 -0
- data/lib/openhab/core/items/color_item.rb +52 -0
- data/lib/openhab/core/items/contact_item.rb +52 -0
- data/lib/openhab/core/items/date_time_item.rb +58 -0
- data/lib/openhab/core/items/dimmer_item.rb +148 -0
- data/lib/openhab/core/items/generic_item.rb +344 -0
- data/lib/openhab/core/items/group_item.rb +174 -0
- data/lib/openhab/core/items/image_item.rb +109 -0
- data/lib/openhab/core/items/location_item.rb +34 -0
- data/lib/openhab/core/items/metadata/hash.rb +390 -0
- data/lib/openhab/core/items/metadata/namespace_hash.rb +469 -0
- data/lib/openhab/core/items/metadata.rb +11 -0
- data/lib/openhab/core/items/number_item.rb +62 -0
- data/lib/openhab/core/items/numeric_item.rb +22 -0
- data/lib/openhab/core/items/persistence.rb +327 -0
- data/lib/openhab/core/items/player_item.rb +66 -0
- data/lib/openhab/core/items/proxy.rb +59 -0
- data/lib/openhab/core/items/registry.rb +66 -0
- data/lib/openhab/core/items/rollershutter_item.rb +68 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +152 -0
- data/lib/openhab/core/items/semantics.rb +476 -0
- data/lib/openhab/core/items/state_storage.rb +53 -0
- data/lib/openhab/core/items/string_item.rb +28 -0
- data/lib/openhab/core/items/switch_item.rb +78 -0
- data/lib/openhab/core/items.rb +114 -0
- data/lib/openhab/core/lazy_array.rb +52 -0
- data/lib/openhab/core/profile_factory.rb +118 -0
- data/lib/openhab/core/script_handling.rb +55 -0
- data/lib/openhab/core/things/channel.rb +48 -0
- data/lib/openhab/core/things/channel_uid.rb +51 -0
- data/lib/openhab/core/things/item_channel_link.rb +33 -0
- data/lib/openhab/core/things/profile_callback.rb +52 -0
- data/lib/openhab/core/things/proxy.rb +69 -0
- data/lib/openhab/core/things/registry.rb +46 -0
- data/lib/openhab/core/things/thing.rb +194 -0
- data/lib/openhab/core/things.rb +22 -0
- data/lib/openhab/core/timer.rb +128 -0
- data/lib/openhab/core/types/comparable_type.rb +23 -0
- data/lib/openhab/core/types/date_time_type.rb +259 -0
- data/lib/openhab/core/types/decimal_type.rb +192 -0
- data/lib/openhab/core/types/hsb_type.rb +183 -0
- data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
- data/lib/openhab/core/types/next_previous_type.rb +34 -0
- data/lib/openhab/core/types/numeric_type.rb +52 -0
- data/lib/openhab/core/types/on_off_type.rb +46 -0
- data/lib/openhab/core/types/open_closed_type.rb +41 -0
- data/lib/openhab/core/types/percent_type.rb +95 -0
- data/lib/openhab/core/types/play_pause_type.rb +38 -0
- data/lib/openhab/core/types/point_type.rb +117 -0
- data/lib/openhab/core/types/quantity_type.rb +327 -0
- data/lib/openhab/core/types/raw_type.rb +26 -0
- data/lib/openhab/core/types/refresh_type.rb +27 -0
- data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
- data/lib/openhab/core/types/stop_move_type.rb +34 -0
- data/lib/openhab/core/types/string_type.rb +76 -0
- data/lib/openhab/core/types/type.rb +117 -0
- data/lib/openhab/core/types/un_def_type.rb +38 -0
- data/lib/openhab/core/types/up_down_type.rb +50 -0
- data/lib/openhab/core/types.rb +69 -0
- data/lib/openhab/core/uid.rb +36 -0
- data/lib/openhab/core.rb +85 -0
- data/lib/openhab/core_ext/java/duration.rb +115 -0
- data/lib/openhab/core_ext/java/local_date.rb +93 -0
- data/lib/openhab/core_ext/java/local_time.rb +106 -0
- data/lib/openhab/core_ext/java/month.rb +59 -0
- data/lib/openhab/core_ext/java/month_day.rb +105 -0
- data/lib/openhab/core_ext/java/period.rb +103 -0
- data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
- data/lib/openhab/core_ext/java/time.rb +58 -0
- data/lib/openhab/core_ext/java/unit.rb +15 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +116 -0
- data/lib/openhab/core_ext/ruby/array.rb +21 -0
- data/lib/openhab/core_ext/ruby/class.rb +15 -0
- data/lib/openhab/core_ext/ruby/date.rb +89 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +190 -0
- data/lib/openhab/core_ext/ruby/range.rb +70 -0
- data/lib/openhab/core_ext/ruby/time.rb +104 -0
- data/lib/openhab/core_ext.rb +18 -0
- data/lib/openhab/dsl/events/watch_event.rb +18 -0
- data/lib/openhab/dsl/events.rb +9 -0
- data/lib/openhab/dsl/gems.rb +3 -0
- data/lib/openhab/dsl/items/builder.rb +618 -0
- data/lib/openhab/dsl/items/ensure.rb +93 -0
- data/lib/openhab/dsl/items/timed_command.rb +236 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +308 -0
- data/lib/openhab/dsl/rules/builder.rb +1373 -0
- data/lib/openhab/dsl/rules/guard.rb +115 -0
- data/lib/openhab/dsl/rules/name_inference.rb +160 -0
- data/lib/openhab/dsl/rules/property.rb +76 -0
- data/lib/openhab/dsl/rules/rule_triggers.rb +96 -0
- data/lib/openhab/dsl/rules/terse.rb +63 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +169 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +57 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +107 -0
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +161 -0
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +164 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +195 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +127 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +56 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +130 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +55 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +155 -0
- data/lib/openhab/dsl/rules/triggers.rb +12 -0
- data/lib/openhab/dsl/rules.rb +29 -0
- data/lib/openhab/dsl/script_handling.rb +55 -0
- data/lib/openhab/dsl/things/builder.rb +263 -0
- data/lib/openhab/dsl/thread_local.rb +48 -0
- data/lib/openhab/dsl/timer_manager.rb +191 -0
- data/lib/openhab/dsl/version.rb +9 -0
- data/lib/openhab/dsl.rb +686 -0
- data/lib/openhab/log.rb +348 -0
- data/lib/openhab/osgi.rb +70 -0
- data/lib/openhab/rspec/configuration.rb +56 -0
- data/lib/openhab/rspec/example_group.rb +90 -0
- data/lib/openhab/rspec/helpers.rb +439 -0
- data/lib/openhab/rspec/hooks.rb +93 -0
- data/lib/openhab/rspec/jruby.rb +46 -0
- data/lib/openhab/rspec/karaf.rb +811 -0
- data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
- data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
- data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
- data/lib/openhab/rspec/mocks/metadata_provider.rb +75 -0
- data/lib/openhab/rspec/mocks/persistence_service.rb +140 -0
- data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +56 -0
- data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
- data/lib/openhab/rspec/mocks/timer.rb +95 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +26 -0
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +27 -0
- data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
- data/lib/openhab/rspec/shell.rb +31 -0
- data/lib/openhab/rspec/suspend_rules.rb +60 -0
- data/lib/openhab/rspec.rb +17 -0
- data/lib/openhab/yard/cli/stats.rb +23 -0
- data/lib/openhab/yard/code_objects/group_object.rb +17 -0
- data/lib/openhab/yard/code_objects/java/base.rb +31 -0
- data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +49 -0
- data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +27 -0
- data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
- data/lib/openhab/yard/html_helper.rb +44 -0
- data/lib/openhab/yard/tags/constant_directive.rb +20 -0
- data/lib/openhab/yard/tags/group_directive.rb +24 -0
- data/lib/openhab/yard/tags/library.rb +3 -0
- data/lib/openhab/yard.rb +32 -0
- metadata +504 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd7a4eed6a2398fd34734d9b3dc15a8f5e2bcc74f7309aede27be29501c21698
|
4
|
+
data.tar.gz: a1f70554ada415e7de0325ea259ac9edcad48355ef6000a4877057fa06b343ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f27aa8940df9441a5318c32d1c0d84f15fdd70b2336cf95dd09383b73b97d14bbc7c924ba3e3df24f48d5f289d410ec1d6d0df9f99a40141ac34d88152e9a76a
|
7
|
+
data.tar.gz: c369de38091c4486a492b88ef990537b5a4cc667becca6be5a99a56227a8a2b0339b14e9ce1e11e6e73b56d8b055d3876917916ee7ec52b66c5b23e85b33a95b
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
#
|
6
|
+
# Access to global actions.
|
7
|
+
#
|
8
|
+
# All OpenHAB's actions including those provided by add-ons are available, notably:
|
9
|
+
# * Audio
|
10
|
+
# * Voice
|
11
|
+
# * Things
|
12
|
+
# * Ephemeris
|
13
|
+
# * Exec
|
14
|
+
# * HTTP
|
15
|
+
# * Ping
|
16
|
+
#
|
17
|
+
# From add-ons, e.g.:
|
18
|
+
# * Transformation
|
19
|
+
# * PersistenceExtensions (see {Items::Persistence})
|
20
|
+
# * NotificationAction (from [OpenHAB Cloud Connector](https://www.openhab.org/addons/integrations/openhabcloud/))
|
21
|
+
#
|
22
|
+
# Global actions are available as "global" methods on {OpenHAB::DSL}, or
|
23
|
+
# explicitly from this {Actions} module, or you can explicitly reference a
|
24
|
+
# specific action.
|
25
|
+
#
|
26
|
+
# Thing-specific actions can be accessed from the {Things::Thing Thing} object.
|
27
|
+
# See {Things::Thing#actions Thing#actions}.
|
28
|
+
#
|
29
|
+
# @example Run the TTS engine and output to the default audio sink. For more information see [Voice](https://www.openhab.org/docs/configuration/multimedia.html#voice)
|
30
|
+
# rule 'Say the time every hour' do
|
31
|
+
# every :hour
|
32
|
+
# run { say "The time is #{TimeOfDay.now}" }
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# rule 'Play an audio file' do
|
36
|
+
# every :hour
|
37
|
+
# run { play_sound "beep.mp3", volume: 100 }
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# play_stream 'example.com'
|
41
|
+
#
|
42
|
+
# @example Send a broadcast notification via the OpenHAB Cloud
|
43
|
+
# rule 'Send an alert' do
|
44
|
+
# changed Alarm_Triggered, to: ON
|
45
|
+
# run { notify 'Red Alert!' }
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# @example Execute an external command
|
49
|
+
# rule 'Run a command' do
|
50
|
+
# every :day
|
51
|
+
# run do
|
52
|
+
# execute_command_line('/bin/true')
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# @example Execute an external command, referencing the Exec module directly
|
57
|
+
# rule 'Run a command' do
|
58
|
+
# every :day
|
59
|
+
# run do
|
60
|
+
# OpenHAB::Core::Actions::Exec::execute_command_line('/bin/true')
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# @example Run a transformation
|
65
|
+
# transform("MAP", "myfan.map", "0")
|
66
|
+
#
|
67
|
+
module Actions
|
68
|
+
OSGi.services("org.openhab.core.model.script.engine.action.ActionService")&.each do |service|
|
69
|
+
java_import service.action_class.ruby_class
|
70
|
+
logger.trace("Loaded ACTION: #{service.action_class}")
|
71
|
+
end
|
72
|
+
# Import common actions
|
73
|
+
%w[Exec HTTP Ping].each { |action| java_import "org.openhab.core.model.script.actions.#{action}" }
|
74
|
+
|
75
|
+
module_function
|
76
|
+
|
77
|
+
#
|
78
|
+
# Send notification to an email or broadcast
|
79
|
+
#
|
80
|
+
# @param msg [String] The notification message to send
|
81
|
+
# @param email [String, nil] The email address to send to. If nil, the message will be broadcast
|
82
|
+
# @param icon [String, Symbol, nil]
|
83
|
+
# @param severity [String, Symbol, nil]
|
84
|
+
#
|
85
|
+
# @return [void]
|
86
|
+
#
|
87
|
+
def notify(msg, email: nil, icon: nil, severity: nil)
|
88
|
+
unless Actions.const_defined?(:NotificationAction)
|
89
|
+
raise NoMethodError, "NotificationAction is not available. Please install the OpenHAB cloud addon"
|
90
|
+
end
|
91
|
+
|
92
|
+
if email
|
93
|
+
NotificationAction.send_notification(email.to_s, msg.to_s, icon&.to_s, severity&.to_s)
|
94
|
+
else
|
95
|
+
NotificationAction.send_broadcast_notification(msg.to_s, icon&.to_s, severity&.to_s)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Say text via OpenHAB Text-To-Speech service, Voice.say()
|
101
|
+
#
|
102
|
+
# @param text [String] The text to say
|
103
|
+
# @param voice [String] Specify a particular voice to use
|
104
|
+
# @param sink [String] Specify a particular sink to output the speech
|
105
|
+
# @param volume [PercentType] Specify the volume for the speech
|
106
|
+
#
|
107
|
+
# @return [void]
|
108
|
+
#
|
109
|
+
def say(text, voice: nil, sink: nil, volume: nil)
|
110
|
+
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
111
|
+
Voice.say(text.to_s, voice&.to_s, sink&.to_s, volume)
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Play an audio file via OpenHAB sound service, Audio.playSound()
|
116
|
+
#
|
117
|
+
# @param filename [String] The sound file to play
|
118
|
+
# @param sink [String] Specify a particular sink to output the speech
|
119
|
+
# @param volume [PercentType] Specify the volume for the speech
|
120
|
+
#
|
121
|
+
# @return [void]
|
122
|
+
#
|
123
|
+
def play_sound(filename, sink: nil, volume: nil)
|
124
|
+
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
125
|
+
Audio.play_sound(sink&.to_s, filename.to_s, volume)
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Play an audio stream from an URL to the given sink(s). Set url to nil if streaming should be stopped
|
130
|
+
#
|
131
|
+
# @param [String] url The URL of the audio stream
|
132
|
+
# @param [String] sink The audio sink, or nil to use the default audio sink
|
133
|
+
#
|
134
|
+
# @return [void]
|
135
|
+
#
|
136
|
+
def play_stream(url, sink: nil)
|
137
|
+
Audio.play_stream(sink&.to_s, url)
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Delegate missing methods to any available global actions.
|
142
|
+
#
|
143
|
+
def method_missing(method, *args, &block)
|
144
|
+
Actions.constants.each do |constant|
|
145
|
+
mod = Actions.const_get(constant)
|
146
|
+
return mod.public_send(method, *args, &block) if mod.respond_to?(method)
|
147
|
+
end
|
148
|
+
|
149
|
+
super
|
150
|
+
end
|
151
|
+
|
152
|
+
# @!visibility private
|
153
|
+
def respond_to_missing?(method_name, _include_private = false)
|
154
|
+
Actions.constants.each do |constant|
|
155
|
+
mod = Actions.const_get(constant)
|
156
|
+
return true if mod.respond_to?(method_name)
|
157
|
+
end
|
158
|
+
|
159
|
+
super
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
#
|
6
|
+
# Manages access to OpenHAB entities
|
7
|
+
#
|
8
|
+
# You can access OpenHAB items and things directly using their name, anywhere `EntityLookup` is available.
|
9
|
+
#
|
10
|
+
# @note Thing UIDs are separated by a colon `:`. Since it is not a valid symbol for an identifier,
|
11
|
+
# it must be replaced with an underscore `_`. So to access `astro:sun:home`, use `astro_sun_home`
|
12
|
+
# as an alternative to `things["astro:sun:home"]`
|
13
|
+
#
|
14
|
+
# @see OpenHAB::DSL.items items[]
|
15
|
+
# @see OpenHAB::DSL.things things[]
|
16
|
+
#
|
17
|
+
# @example Accessing Items and Groups
|
18
|
+
# gAll_Lights # Access the gAll_Lights group. It is the same as items["gAll_Lights"]
|
19
|
+
# Kitchen_Light.on # The OpenHAB object for the Kitchen_Light item and send an ON command
|
20
|
+
#
|
21
|
+
# @example Accessing Things
|
22
|
+
# smtp_mail_local.send_mail('me@example.com', 'Subject', 'Dear Person, ...')
|
23
|
+
# # Is equivalent to:
|
24
|
+
# things['smtp:mail:local'].send_mail('me@example.com', 'Subject', 'Dear Person, ...')
|
25
|
+
#
|
26
|
+
module EntityLookup
|
27
|
+
#
|
28
|
+
# Automatically looks up OpenHAB items and things in appropriate registries
|
29
|
+
#
|
30
|
+
# @return [GenericItem, Things::Thing, nil]
|
31
|
+
#
|
32
|
+
def method_missing(method, *args, &block)
|
33
|
+
logger.trace("method missing, performing OpenHab Lookup for: #{method}")
|
34
|
+
EntityLookup.lookup_entity(method) || super
|
35
|
+
end
|
36
|
+
|
37
|
+
# @!visibility private
|
38
|
+
def respond_to_missing?(method_name, _include_private = false)
|
39
|
+
logger.trace("Checking if OpenHAB entities exist for #{method_name}")
|
40
|
+
method_name = method_name.to_s if method_name.is_a?(Symbol)
|
41
|
+
|
42
|
+
method_name == "scriptLoaded" ||
|
43
|
+
method_name == "scriptUnloaded" ||
|
44
|
+
EntityLookup.lookup_entity(method_name) ||
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Looks up an OpenHAB entity
|
50
|
+
# items are checked first, then things
|
51
|
+
#
|
52
|
+
# @!visibility private
|
53
|
+
#
|
54
|
+
# @param [String] name of entity to lookup in item or thing registry
|
55
|
+
#
|
56
|
+
# @return [GenericItem, Things::Thing, nil]
|
57
|
+
#
|
58
|
+
def self.lookup_entity(name)
|
59
|
+
lookup_item(name) || lookup_thing_const(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Looks up a Thing in the OpenHAB registry
|
64
|
+
#
|
65
|
+
# @!visibility private
|
66
|
+
#
|
67
|
+
# @param [String] uid name of Thing to lookup in Thing registry
|
68
|
+
#
|
69
|
+
# @return [Things::Thing, nil]
|
70
|
+
#
|
71
|
+
def self.lookup_thing(uid)
|
72
|
+
logger.trace("Looking up thing '#{uid}'")
|
73
|
+
uid = uid.to_s if uid.is_a?(Symbol)
|
74
|
+
|
75
|
+
uid = generate_thing_uid(uid) unless uid.is_a?(org.openhab.core.thing.ThingUID)
|
76
|
+
thing = $things.get(uid)
|
77
|
+
return unless thing
|
78
|
+
|
79
|
+
logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
|
80
|
+
Things::Proxy.new(thing)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Looks up a Thing in the OpenHAB registry replacing `_` with `:`
|
85
|
+
#
|
86
|
+
# @!visibility private
|
87
|
+
#
|
88
|
+
# @param [String] name of Thing to lookup in Thing registry
|
89
|
+
#
|
90
|
+
# @return [Things::Thing, nil]
|
91
|
+
#
|
92
|
+
def self.lookup_thing_const(name)
|
93
|
+
name = name.to_s if name.is_a?(Symbol)
|
94
|
+
|
95
|
+
if name.is_a?(String)
|
96
|
+
# Thing UIDs have at least 3 segments, separated by `_`
|
97
|
+
return if name.count("_") < 2
|
98
|
+
|
99
|
+
# Convert from _ syntax to :
|
100
|
+
name = name.tr("_", ":")
|
101
|
+
end
|
102
|
+
lookup_thing(name)
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Lookup OpenHAB items in item registry
|
107
|
+
#
|
108
|
+
# @!visibility private
|
109
|
+
#
|
110
|
+
# @param [String] name of item to lookup
|
111
|
+
#
|
112
|
+
# @return [GenericItem, nil]
|
113
|
+
#
|
114
|
+
def self.lookup_item(name)
|
115
|
+
logger.trace("Looking up item '#{name}'")
|
116
|
+
name = name.to_s if name.is_a?(Symbol)
|
117
|
+
item = $ir.get(name)
|
118
|
+
Items::Proxy.new(item) unless item.nil?
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# Returns a ThingUID given a string like object
|
123
|
+
#
|
124
|
+
# @!visibility private
|
125
|
+
#
|
126
|
+
# @return [Things::ThingUID]
|
127
|
+
#
|
128
|
+
def self.generate_thing_uid(uid)
|
129
|
+
org.openhab.core.thing.ThingUID.new(*uid.split(":"))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Implements const_missing to return OpenHAB items or things if mapping to missing name if they exist
|
137
|
+
#
|
138
|
+
# @param [String] name Capital string that was not set as a constant and to be looked up
|
139
|
+
#
|
140
|
+
# @return [Object] OpenHAB Item or Thing if their name exist in OpenHAB item and thing regestries
|
141
|
+
#
|
142
|
+
def Object.const_missing(name)
|
143
|
+
OpenHAB::Core::EntityLookup.lookup_entity(name) || super
|
144
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.events.AbstractEvent
|
7
|
+
|
8
|
+
# Add attachments event data.
|
9
|
+
class AbstractEvent
|
10
|
+
# @return [Object]
|
11
|
+
attr_accessor :attachment
|
12
|
+
|
13
|
+
alias_method :inspect, :to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.thing.link.dto.ItemChannelLinkDTO
|
7
|
+
|
8
|
+
# Strictly speaking this class isn't an event, but it's accessed from an AbstractItemChannelLinkEvent
|
9
|
+
|
10
|
+
# Adds methods to core OpenHAB ItemChannelLinkDTO to make it more natural in Ruby
|
11
|
+
class ItemChannelLinkDTO
|
12
|
+
#
|
13
|
+
# @!attribute [r] item_name
|
14
|
+
# @return [String] The name of the item that was linked or unlinked.
|
15
|
+
#
|
16
|
+
alias_method :item_name, :itemName
|
17
|
+
|
18
|
+
#
|
19
|
+
# @!attribute [r] item
|
20
|
+
# @return [GenericItem] The item that was linked or unlinked
|
21
|
+
#
|
22
|
+
def item
|
23
|
+
EntityLookup.lookup_item(itemName)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# @!attribute [r] channel_uid
|
28
|
+
# @return [Things::ChannelUID] The UID of the channel that was linked or unlinked.
|
29
|
+
#
|
30
|
+
def channel_uid
|
31
|
+
Things::ChannelUID.new(channelUID)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "item_event"
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module Core
|
7
|
+
module Events
|
8
|
+
java_import org.openhab.core.items.events.ItemCommandEvent
|
9
|
+
|
10
|
+
# Adds methods to core OpenHAB ItemCommandEvent to make it more natural in Ruby
|
11
|
+
class ItemCommandEvent < ItemEvent
|
12
|
+
# @!attribute [r] command
|
13
|
+
# @return [Type] The command sent to the item.
|
14
|
+
alias_method :command, :item_command
|
15
|
+
|
16
|
+
# @!method refresh?
|
17
|
+
# Check if `self == REFRESH`
|
18
|
+
# @return [true,false]
|
19
|
+
|
20
|
+
# @!method on?
|
21
|
+
# Check if `self == ON`
|
22
|
+
# @return [true,false]
|
23
|
+
|
24
|
+
# @!method off?
|
25
|
+
# Check if `self == OFF`
|
26
|
+
# @return [true,false]
|
27
|
+
|
28
|
+
# @!method up?
|
29
|
+
# Check if `self == UP`
|
30
|
+
# @return [true,false]
|
31
|
+
|
32
|
+
# @!method down?
|
33
|
+
# Check if `self == DOWN`
|
34
|
+
# @return [true,false]
|
35
|
+
|
36
|
+
# @!method stop?
|
37
|
+
# Check if `self == STOP`
|
38
|
+
# @return [true,false]
|
39
|
+
|
40
|
+
# @!method move?
|
41
|
+
# Check if `self == MOVE`
|
42
|
+
# @return [true,false]
|
43
|
+
|
44
|
+
# @!method increase?
|
45
|
+
# Check if `self == INCREASE`
|
46
|
+
# @return [true,false]
|
47
|
+
|
48
|
+
# @!method decrease?
|
49
|
+
# Check if `self == DECREASE`
|
50
|
+
# @return [true,false]
|
51
|
+
|
52
|
+
# @!method play?
|
53
|
+
# Check if `self == PLAY`
|
54
|
+
# @return [true,false]
|
55
|
+
|
56
|
+
# @!method pause?
|
57
|
+
# Check if `self == PAUSE`
|
58
|
+
# @return [true,false]
|
59
|
+
|
60
|
+
# @!method rewind?
|
61
|
+
# Check if `self == REWIND`
|
62
|
+
# @return [true,false]
|
63
|
+
|
64
|
+
# @!method fast_forward?
|
65
|
+
# Check if `self == FASTFORWARD`
|
66
|
+
# @return [true,false]
|
67
|
+
|
68
|
+
# @!method next?
|
69
|
+
# Check if `self == NEXT`
|
70
|
+
# @return [true,false]
|
71
|
+
|
72
|
+
# @!method previous?
|
73
|
+
# Check if `self == PREVIOUS`
|
74
|
+
# @return [true,false]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.items.events.ItemEvent
|
7
|
+
|
8
|
+
#
|
9
|
+
# Adds methods to core OpenHAB ItemEvent to make it more natural in Ruby
|
10
|
+
#
|
11
|
+
class ItemEvent < AbstractEvent
|
12
|
+
#
|
13
|
+
# @!attribute [r] item
|
14
|
+
# @return [GenericItem] The item that triggered this event.
|
15
|
+
#
|
16
|
+
def item
|
17
|
+
EntityLookup.lookup_item(item_name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "item_state_event"
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module Core
|
7
|
+
module Events
|
8
|
+
java_import org.openhab.core.items.events.ItemStateChangedEvent
|
9
|
+
|
10
|
+
#
|
11
|
+
# Adds methods to core OpenHAB ItemStateChangedEvent to make it more natural in Ruby
|
12
|
+
#
|
13
|
+
class ItemStateChangedEvent < ItemEvent
|
14
|
+
include ItemState
|
15
|
+
|
16
|
+
#
|
17
|
+
# Check if state was == UNDEF
|
18
|
+
#
|
19
|
+
# @return [true,false] True if the state is UNDEF, false otherwise
|
20
|
+
#
|
21
|
+
def was_undef?
|
22
|
+
old_item_state == UNDEF
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Check if state was == NULL
|
27
|
+
#
|
28
|
+
# @return [true,false] True if the state is NULL, false otherwise
|
29
|
+
def was_null?
|
30
|
+
old_item_state == NULL
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Check if state was defined (not UNDEF or NULL)
|
35
|
+
#
|
36
|
+
# @return [true,false] True if state is not UNDEF or NULL
|
37
|
+
#
|
38
|
+
def was?
|
39
|
+
!old_item_state.is_a?(UnDefType)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# @!attribute [r] was
|
44
|
+
# @return [State, nil] The state of the item if it was not {UNDEF} or {NULL}, `nil` otherwise.
|
45
|
+
#
|
46
|
+
def was
|
47
|
+
old_item_state if was?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.items.events.ItemStateEvent
|
7
|
+
|
8
|
+
# Helpers common to {ItemStateEvent} and {ItemStateChangedEvent}.
|
9
|
+
module ItemState
|
10
|
+
#
|
11
|
+
# Check if the state == UNDEF
|
12
|
+
#
|
13
|
+
# @return [true,false] True if the state is UNDEF, false otherwise
|
14
|
+
#
|
15
|
+
def undef?
|
16
|
+
item_state == UNDEF
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Check if the state == NULL
|
21
|
+
#
|
22
|
+
# @return [true,false] True if the state is NULL, false otherwise
|
23
|
+
def null?
|
24
|
+
item_state == NULL
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Check if the state is defined (not UNDEF or NULL)
|
29
|
+
#
|
30
|
+
# @return [true,false] True if state is not UNDEF or NULL
|
31
|
+
#
|
32
|
+
def state?
|
33
|
+
!item_state.is_a?(UnDefType)
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# @!attribute [r] state
|
38
|
+
# @return [State, nil] The state of the item if it is not {UNDEF} or {NULL}, `nil` otherwise.
|
39
|
+
#
|
40
|
+
def state
|
41
|
+
item_state if state?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# {AbstractEvent} sent when an item's state is updated (regardless of if it changed or not).
|
46
|
+
class ItemStateEvent < ItemEvent
|
47
|
+
include ItemState
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.thing.dto.AbstractThingDTO
|
7
|
+
|
8
|
+
# Strictly speaking this class isn't an event, but it's accessed from an AbstractThingRegistryEvent
|
9
|
+
|
10
|
+
# Adds methods to core OpenHAB AbstractThingDTO to make it more natural in Ruby
|
11
|
+
class AbstractThingDTO
|
12
|
+
# @!method uid
|
13
|
+
# The thing's UID
|
14
|
+
# @return [String]
|
15
|
+
alias_method :uid, :UID
|
16
|
+
|
17
|
+
# @!method thing_type_uid
|
18
|
+
# The thing type's UID
|
19
|
+
# @return [String]
|
20
|
+
alias_method :thing_type_uid, :thingTypeUID
|
21
|
+
|
22
|
+
# @!method bridge_uid
|
23
|
+
# The bridge's UID
|
24
|
+
# @return [String]
|
25
|
+
alias_method :bridge_uid, :bridgeUID
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.thing.events.ThingStatusInfoChangedEvent,
|
7
|
+
org.openhab.core.thing.events.ThingStatusInfoEvent
|
8
|
+
|
9
|
+
# The {AbstractEvent} sent when a {Things::Thing}'s status has changed.
|
10
|
+
class ThingStatusInfoChangedEvent < AbstractEvent
|
11
|
+
# @!attribute [r] uid
|
12
|
+
# @return [Things::ThingUID] The UID of the [Things::Thing] that triggered this event.
|
13
|
+
alias_method :uid, :get_thing_uid
|
14
|
+
# @!attribute [r] was
|
15
|
+
# @return [Things::ThingStatusInfo] The thing's prior status.
|
16
|
+
alias_method :was, :get_old_status_info
|
17
|
+
# @!attribute [r] status
|
18
|
+
# @return [Things::ThingStatusInfo] The thing's status.
|
19
|
+
alias_method :status, :status_info
|
20
|
+
|
21
|
+
#
|
22
|
+
# @!attribute [r] thing
|
23
|
+
# @return [Things::Thing] The thing that triggered this event.
|
24
|
+
#
|
25
|
+
def thing
|
26
|
+
EntityLookup.lookup_thing(uid)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# The {AbstractEvent} sent when a {Things::Thing}'s status is set.
|
31
|
+
class ThingStatusInfoEvent < AbstractEvent
|
32
|
+
#
|
33
|
+
# @!attribute [r] uid
|
34
|
+
# @return [Things::ThingUID] The UID of the [Things::Thing] that triggered this event.
|
35
|
+
#
|
36
|
+
alias_method :uid, :get_thing_uid
|
37
|
+
#
|
38
|
+
# @!attribute [r] status
|
39
|
+
# @return [Things::ThingStatusInfo] The thing's status.
|
40
|
+
#
|
41
|
+
alias_method :status, :status_info
|
42
|
+
|
43
|
+
#
|
44
|
+
# @!attribute [r] thing
|
45
|
+
# @return [Things::Thing] The thing that triggered this event.
|
46
|
+
#
|
47
|
+
def thing
|
48
|
+
EntityLookup.lookup_thing(uid)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Items
|
6
|
+
class << self
|
7
|
+
# @!visibility private
|
8
|
+
def prepend_accepted_data_types
|
9
|
+
concrete_item_classes.each do |k|
|
10
|
+
k.prepend(AcceptedDataTypes)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module AcceptedDataTypes
|
16
|
+
# @see GenericItem#accepted_command_types
|
17
|
+
def accepted_command_types
|
18
|
+
super.map { |k| k.is_a?(java.lang.Class) ? k.ruby_class : k }
|
19
|
+
end
|
20
|
+
|
21
|
+
# @see GenericItem#accepted_data_types
|
22
|
+
def accepted_data_types
|
23
|
+
super.map { |k| k.is_a?(java.lang.Class) ? k.ruby_class : k }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
private_constant :AcceptedDataTypes
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|