openhab-jrubyscripting 5.0.0.rc10 → 5.0.0.rc11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/actions/audio.rb +47 -0
- data/lib/openhab/core/actions/ephemeris.rb +39 -0
- data/lib/openhab/core/actions/exec.rb +51 -0
- data/lib/openhab/core/actions/http.rb +80 -0
- data/lib/openhab/core/actions/ping.rb +30 -0
- data/lib/openhab/core/actions/transformation.rb +32 -0
- data/lib/openhab/core/actions/voice.rb +36 -0
- data/lib/openhab/core/actions.rb +23 -120
- data/lib/openhab/core/{events → dto}/item_channel_link.rb +1 -4
- data/lib/openhab/core/{events → dto}/thing.rb +10 -12
- data/lib/openhab/core/dto.rb +11 -0
- data/lib/openhab/core/entity_lookup.rb +1 -1
- data/lib/openhab/core/events/abstract_event.rb +1 -0
- data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
- data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
- data/lib/openhab/core/events/item_command_event.rb +1 -1
- data/lib/openhab/core/events/item_state_changed_event.rb +6 -6
- data/lib/openhab/core/events/item_state_event.rb +6 -6
- data/lib/openhab/core/events/thing_status_info_event.rb +8 -6
- data/lib/openhab/core/items/generic_item.rb +2 -1
- data/lib/openhab/core/items/persistence.rb +52 -18
- data/lib/openhab/core/items/player_item.rb +1 -1
- data/lib/openhab/core/items/proxy.rb +20 -14
- data/lib/openhab/core/items/registry.rb +2 -0
- data/lib/openhab/core/items.rb +3 -3
- data/lib/openhab/core/profile_factory.rb +3 -1
- data/lib/openhab/core/proxy.rb +125 -0
- data/lib/openhab/core/things/links/provider.rb +1 -1
- data/lib/openhab/core/things/proxy.rb +8 -0
- data/lib/openhab/core/types/date_time_type.rb +2 -1
- data/lib/openhab/core/types/decimal_type.rb +1 -1
- data/lib/openhab/core/types/un_def_type.rb +2 -2
- data/lib/openhab/core/value_cache.rb +1 -1
- data/lib/openhab/core_ext/ephemeris.rb +53 -0
- data/lib/openhab/core_ext/java/class.rb +1 -1
- data/lib/openhab/core_ext/java/duration.rb +25 -1
- data/lib/openhab/core_ext/java/local_date.rb +2 -0
- data/lib/openhab/core_ext/java/month_day.rb +2 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +85 -0
- data/lib/openhab/core_ext/ruby/date.rb +2 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +1 -0
- data/lib/openhab/core_ext/ruby/time.rb +1 -0
- data/lib/openhab/dsl/debouncer.rb +259 -0
- data/lib/openhab/dsl/items/builder.rb +4 -2
- data/lib/openhab/dsl/items/timed_command.rb +31 -13
- data/lib/openhab/dsl/rules/automation_rule.rb +28 -21
- data/lib/openhab/dsl/rules/builder.rb +357 -37
- data/lib/openhab/dsl/rules/guard.rb +12 -54
- data/lib/openhab/dsl/rules/name_inference.rb +11 -0
- data/lib/openhab/dsl/rules/property.rb +3 -4
- data/lib/openhab/dsl/rules/terse.rb +4 -1
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +5 -6
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +19 -31
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +22 -30
- data/lib/openhab/dsl/things/builder.rb +1 -1
- data/lib/openhab/dsl/thread_local.rb +1 -0
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +224 -3
- data/lib/openhab/rspec/hooks.rb +5 -2
- data/lib/openhab/rspec/karaf.rb +7 -0
- data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
- data/lib/openhab/rspec/mocks/space.rb +23 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +16 -4
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +1 -13
- data/lib/openhab/rspec/suspend_rules.rb +1 -14
- data/lib/openhab/yard/base_helper.rb +19 -0
- data/lib/openhab/yard/code_objects/group_object.rb +9 -3
- data/lib/openhab/yard/coderay.rb +17 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +10 -1
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +3 -0
- data/lib/openhab/yard/html_helper.rb +49 -15
- data/lib/openhab/yard/markdown_helper.rb +135 -0
- data/lib/openhab/yard.rb +6 -0
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3911eb787dc73ea31109aa6d4d8c3896a1019b381a70030f152c668f0b8f2e
|
4
|
+
data.tar.gz: ebd2d7005e9f17827a4bf58d38b7fc2476a497cb428aab0270290c3c98461b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4c1df793cd44700467728c63df6ba9d12ecf7111fc7daf2b9a8f4953c68575082f9f4b87f70a42bfedcc9af70d4537e45b6fb2d8b78ac8e7e3f7cca22aaf4b
|
7
|
+
data.tar.gz: de1c8f5847bbbeb3eed3268ceedc2a61213b4f6ab269372a08bd4d8217f6b384a2c62b5ceb1f9de2777d264d0d6eb4e02fde6f245fa4fcc0dc03d068041a11bb
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see https://www.openhab.org/docs/configuration/multimedia.html#actions-2 Audio Actions
|
7
|
+
class Audio
|
8
|
+
class << self
|
9
|
+
#
|
10
|
+
# Play an audio file via openHAB sound service, Audio.playSound()
|
11
|
+
#
|
12
|
+
# @param filename [String] The sound file to play
|
13
|
+
# @param sink [String] Specify a particular sink to output the speech
|
14
|
+
# @param volume [PercentType] Specify the volume for the speech
|
15
|
+
#
|
16
|
+
# @return [void]
|
17
|
+
#
|
18
|
+
# @example Play an audio file
|
19
|
+
# rule 'Play an audio file' do
|
20
|
+
# every :hour
|
21
|
+
# run { Audio.play_sound "beep.mp3", volume: 100 }
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
def play_sound(filename, sink: nil, volume: nil)
|
25
|
+
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
26
|
+
playSound(sink&.to_s, filename.to_s, volume)
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Play an audio stream from an URL to the given sink(s). Set url to nil if streaming should be stopped
|
31
|
+
#
|
32
|
+
# @param [String] url The URL of the audio stream
|
33
|
+
# @param [String] sink The audio sink, or nil to use the default audio sink
|
34
|
+
#
|
35
|
+
# @return [void]
|
36
|
+
#
|
37
|
+
# @example Play an audio stream
|
38
|
+
# Audio.play_stream 'example.com'
|
39
|
+
#
|
40
|
+
def play_stream(url, sink: nil)
|
41
|
+
playStream(sink&.to_s, url)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see CoreExt::Ephemeris
|
7
|
+
class Ephemeris
|
8
|
+
class << self
|
9
|
+
#
|
10
|
+
# Human readable name of the given holiday
|
11
|
+
#
|
12
|
+
# @param [Symbol, #holiday, nil] holiday
|
13
|
+
# @return [String, nil]
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# Ephemeris.holiday_name(Date.today) # => "Christmas"
|
17
|
+
# Ephemeris.holiday_name(:christmas) # => "Christmas"
|
18
|
+
#
|
19
|
+
def holiday_name(holiday)
|
20
|
+
holiday = holiday.holiday if holiday.respond_to?(:holiday)
|
21
|
+
return nil if holiday.nil?
|
22
|
+
|
23
|
+
::Ephemeris.get_holiday_description(to_holiday_property_key(holiday))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def to_holiday_property_key(holiday)
|
29
|
+
holiday = holiday.to_s
|
30
|
+
return holiday.upcase unless holiday.include?(".")
|
31
|
+
|
32
|
+
religion, holiday = holiday.split(/\.([^.]*)$/)
|
33
|
+
:"#{religion}.#{holiday.upcase}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see https://www.openhab.org/docs/configuration/actions.html#exec-actions Exec Actions
|
7
|
+
class Exec
|
8
|
+
class << self # rubocop:disable Lint/EmptyClass
|
9
|
+
# @!method execute_command_line
|
10
|
+
#
|
11
|
+
# @return [void]
|
12
|
+
#
|
13
|
+
# @overload execute_command_line(command_line)
|
14
|
+
#
|
15
|
+
# Executes a command on the command line without waiting for the
|
16
|
+
# command to complete.
|
17
|
+
#
|
18
|
+
# @param [String] command_line
|
19
|
+
# @return [void]
|
20
|
+
#
|
21
|
+
# @example Execute an external command
|
22
|
+
# rule 'Run a command' do
|
23
|
+
# every :day
|
24
|
+
# run do
|
25
|
+
# Exec.execute_command_line('/bin/true')
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# @overload execute_command_line(timeout, command_line)
|
30
|
+
#
|
31
|
+
# Executes a command on the command and waits timeout seconds for
|
32
|
+
# the command to complete, returning the output from the command
|
33
|
+
# as a String.
|
34
|
+
#
|
35
|
+
# @param [Duration] timeout
|
36
|
+
# @param [String] command_line
|
37
|
+
# @return [String]
|
38
|
+
#
|
39
|
+
# @example Execute an external command and process its results
|
40
|
+
# rule 'Run a command' do
|
41
|
+
# every :day
|
42
|
+
# run do
|
43
|
+
# TodaysHoliday_String.update(Exec.execute_command_line(5.seconds, '/home/cody/determine_holiday.rb')
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see https://www.openhab.org/docs/configuration/actions.html#http-actions HTTP Actions
|
7
|
+
class HTTP
|
8
|
+
class << self
|
9
|
+
#
|
10
|
+
# Sends an HTTP GET request and returns the result as a String.
|
11
|
+
#
|
12
|
+
# @param [String] url
|
13
|
+
# @param [Hash<String, String>] headers
|
14
|
+
# @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
|
15
|
+
# @return [String] the response body
|
16
|
+
# @return [nil] if an error occurred
|
17
|
+
#
|
18
|
+
def send_http_get_request(url, headers: {}, timeout: nil)
|
19
|
+
timeout ||= 5_000
|
20
|
+
timeout = timeout.to_millis if timeout.is_a?(Duration)
|
21
|
+
|
22
|
+
sendHttpGetRequest(url, headers, timeout)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Sends an HTTP PUT request and returns the result as a String.
|
27
|
+
#
|
28
|
+
# @param [String] url
|
29
|
+
# @param [String] content_type
|
30
|
+
# @param [String] content
|
31
|
+
# @param [Hash<String, String>] headers
|
32
|
+
# @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
|
33
|
+
# @return [String] the response body
|
34
|
+
# @return [nil] if an error occurred
|
35
|
+
#
|
36
|
+
def send_http_put_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
|
37
|
+
timeout ||= 1_000
|
38
|
+
timeout = timeout.to_millis if timeout.is_a?(Duration)
|
39
|
+
|
40
|
+
sendHttpPutRequest(url, content_type, content, headers, timeout)
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Sends an HTTP POST request and returns the result as a String.
|
45
|
+
#
|
46
|
+
# @param [String] url
|
47
|
+
# @param [String] content_type
|
48
|
+
# @param [String] content
|
49
|
+
# @param [Hash<String, String>] headers
|
50
|
+
# @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
|
51
|
+
# @return [String] the response body
|
52
|
+
# @return [nil] if an error occurred
|
53
|
+
#
|
54
|
+
def send_http_post_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
|
55
|
+
timeout ||= 1_000
|
56
|
+
timeout = timeout.to_millis if timeout.is_a?(Duration)
|
57
|
+
|
58
|
+
sendHttpPostRequest(url, content_type, content, headers, timeout)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Sends an HTTP DELETE request and returns the result as a String.
|
63
|
+
#
|
64
|
+
# @param [String] url
|
65
|
+
# @param [Hash<String, String>] headers
|
66
|
+
# @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
|
67
|
+
# @return [String] the response body
|
68
|
+
# @return [nil] if an error occurred
|
69
|
+
#
|
70
|
+
def send_http_delete_request(url, headers: {}, timeout: nil)
|
71
|
+
timeout ||= 1_000
|
72
|
+
timeout = timeout.to_millis if timeout.is_a?(Duration)
|
73
|
+
|
74
|
+
sendHttpDeleteRequest(url, headers, timeout)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see org.openhab.core.model.script.actions.Ping
|
7
|
+
class Ping
|
8
|
+
class << self
|
9
|
+
#
|
10
|
+
# Checks the vitality of host.
|
11
|
+
#
|
12
|
+
# If port is `nil`, a regular ping is issued. If other ports are
|
13
|
+
# specified we try to open a new Socket with the given timeout.
|
14
|
+
#
|
15
|
+
# @param [String] host
|
16
|
+
# @param [int, nil] port
|
17
|
+
# @param [Duration, Integer, nil] timeout Connect timeout (in milliseconds, if given as an Integer)
|
18
|
+
# @return [true, false]
|
19
|
+
#
|
20
|
+
def check_vitality(host, port = nil, timeout = nil)
|
21
|
+
port ||= 0
|
22
|
+
timeout ||= 0
|
23
|
+
timeout = timeout.to_millis if timeout.is_a?(Duration)
|
24
|
+
checkVitality(host, port, timeout)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see org.openhab.core.transform.actions.Transformation
|
7
|
+
class Transformation
|
8
|
+
class << self
|
9
|
+
# @!visibility private
|
10
|
+
alias_method :transform_raw, :transform if instance_methods.include?(:say)
|
11
|
+
|
12
|
+
#
|
13
|
+
# Applies a transformation of a given type with some function to a value.
|
14
|
+
#
|
15
|
+
# @param [String, Symbol] type The transformation type, e.g. REGEX
|
16
|
+
# or MAP
|
17
|
+
# @param [String, Symbol] function The function to call. This value depends
|
18
|
+
# on the transformation type
|
19
|
+
# @param [String] value The value to apply the transformation to
|
20
|
+
# @return [String] the transformed value, or the original value if an error occurred
|
21
|
+
#
|
22
|
+
# @example Run a transformation
|
23
|
+
# Transformation.transform(:map, "myfan.map", 0)
|
24
|
+
#
|
25
|
+
def transform(type, function, value)
|
26
|
+
transform_raw(type.to_s.upcase, function.to_s, value.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# @see https://www.openhab.org/docs/configuration/multimedia.html#actions-3 Voice Actions
|
7
|
+
class Voice
|
8
|
+
class << self
|
9
|
+
# @!visibility private
|
10
|
+
alias_method :raw_say, :say if instance_methods.include?(:say)
|
11
|
+
|
12
|
+
#
|
13
|
+
# Say text via openHAB Text-To-Speech service, Voice.say()
|
14
|
+
#
|
15
|
+
# @param text [String] The text to say
|
16
|
+
# @param voice [String] Specify a particular voice to use
|
17
|
+
# @param sink [String] Specify a particular sink to output the speech
|
18
|
+
# @param volume [PercentType] Specify the volume for the speech
|
19
|
+
#
|
20
|
+
# @return [void]
|
21
|
+
#
|
22
|
+
# @example Run the TTS engine and output to the default audio sink.
|
23
|
+
# rule 'Say the time every hour' do
|
24
|
+
# every :hour
|
25
|
+
# run { Voice.say "The time is #{TimeOfDay.now}" }
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
def say(text, voice: nil, sink: nil, volume: nil)
|
29
|
+
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
30
|
+
raw_say(text.to_s, voice&.to_s, sink&.to_s, volume)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/openhab/core/actions.rb
CHANGED
@@ -6,64 +6,24 @@ module OpenHAB
|
|
6
6
|
# Access to global actions.
|
7
7
|
#
|
8
8
|
# All openHAB's actions including those provided by add-ons are available, notably:
|
9
|
-
# * Audio
|
10
|
-
# *
|
11
|
-
# *
|
12
|
-
# *
|
13
|
-
# *
|
14
|
-
# *
|
15
|
-
# *
|
9
|
+
# * {Audio}
|
10
|
+
# * {CoreExt::Ephemeris Ephemeris}
|
11
|
+
# * {Exec}
|
12
|
+
# * {HTTP}
|
13
|
+
# * {Items::Persistence PersistenceExtensions}
|
14
|
+
# * {Ping}
|
15
|
+
# * {Items::Semantics Semantics}
|
16
|
+
# * {Transformation}
|
17
|
+
# * {Voice}
|
16
18
|
#
|
17
19
|
# From add-ons, e.g.:
|
18
|
-
# *
|
19
|
-
#
|
20
|
-
#
|
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.
|
20
|
+
# * NotificationAction (from
|
21
|
+
# [openHAB Cloud Connector](https://www.openhab.org/addons/integrations/openhabcloud/);
|
22
|
+
# see {notify notify})
|
25
23
|
#
|
26
24
|
# Thing-specific actions can be accessed from the {Things::Thing Thing} object.
|
27
25
|
# See {Things::Thing#actions Thing#actions}.
|
28
26
|
#
|
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
27
|
module Actions
|
68
28
|
OSGi.services("org.openhab.core.model.script.engine.action.ActionService")&.each do |service|
|
69
29
|
action_class = service.action_class
|
@@ -91,18 +51,24 @@ module OpenHAB
|
|
91
51
|
module_function
|
92
52
|
|
93
53
|
#
|
94
|
-
# Send notification
|
54
|
+
# Send a notification.
|
95
55
|
#
|
96
|
-
# @param msg [String] The
|
97
|
-
# @param email [String, nil] The email address to send to. If nil
|
56
|
+
# @param msg [String] The message to send.
|
57
|
+
# @param email [String, nil] The email address to send to. If `nil`,
|
58
|
+
# the message will be broadcast.
|
98
59
|
# @param icon [String, Symbol, nil]
|
99
60
|
# @param severity [String, Symbol, nil]
|
100
|
-
#
|
101
61
|
# @return [void]
|
102
62
|
#
|
63
|
+
# @example Send a broadcast notification via openHAB Cloud
|
64
|
+
# rule 'Send an alert' do
|
65
|
+
# changed Alarm_Triggered, to: ON
|
66
|
+
# run { notify 'Red Alert!' }
|
67
|
+
# end
|
68
|
+
#
|
103
69
|
def notify(msg, email: nil, icon: nil, severity: nil)
|
104
70
|
unless Actions.const_defined?(:NotificationAction)
|
105
|
-
raise
|
71
|
+
raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon."
|
106
72
|
end
|
107
73
|
|
108
74
|
if email
|
@@ -111,69 +77,6 @@ module OpenHAB
|
|
111
77
|
NotificationAction.send_broadcast_notification(msg.to_s, icon&.to_s, severity&.to_s)
|
112
78
|
end
|
113
79
|
end
|
114
|
-
|
115
|
-
#
|
116
|
-
# Say text via openHAB Text-To-Speech service, Voice.say()
|
117
|
-
#
|
118
|
-
# @param text [String] The text to say
|
119
|
-
# @param voice [String] Specify a particular voice to use
|
120
|
-
# @param sink [String] Specify a particular sink to output the speech
|
121
|
-
# @param volume [PercentType] Specify the volume for the speech
|
122
|
-
#
|
123
|
-
# @return [void]
|
124
|
-
#
|
125
|
-
def say(text, voice: nil, sink: nil, volume: nil)
|
126
|
-
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
127
|
-
Voice.say(text.to_s, voice&.to_s, sink&.to_s, volume)
|
128
|
-
end
|
129
|
-
|
130
|
-
#
|
131
|
-
# Play an audio file via openHAB sound service, Audio.playSound()
|
132
|
-
#
|
133
|
-
# @param filename [String] The sound file to play
|
134
|
-
# @param sink [String] Specify a particular sink to output the speech
|
135
|
-
# @param volume [PercentType] Specify the volume for the speech
|
136
|
-
#
|
137
|
-
# @return [void]
|
138
|
-
#
|
139
|
-
def play_sound(filename, sink: nil, volume: nil)
|
140
|
-
volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
|
141
|
-
Audio.play_sound(sink&.to_s, filename.to_s, volume)
|
142
|
-
end
|
143
|
-
|
144
|
-
#
|
145
|
-
# Play an audio stream from an URL to the given sink(s). Set url to nil if streaming should be stopped
|
146
|
-
#
|
147
|
-
# @param [String] url The URL of the audio stream
|
148
|
-
# @param [String] sink The audio sink, or nil to use the default audio sink
|
149
|
-
#
|
150
|
-
# @return [void]
|
151
|
-
#
|
152
|
-
def play_stream(url, sink: nil)
|
153
|
-
Audio.play_stream(sink&.to_s, url)
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Delegate missing methods to any available global actions.
|
158
|
-
#
|
159
|
-
def method_missing(method, *args, &block)
|
160
|
-
Actions.constants.each do |constant|
|
161
|
-
mod = Actions.const_get(constant)
|
162
|
-
return mod.public_send(method, *args, &block) if mod.respond_to?(method)
|
163
|
-
end
|
164
|
-
|
165
|
-
super
|
166
|
-
end
|
167
|
-
|
168
|
-
# @!visibility private
|
169
|
-
def respond_to_missing?(method_name, _include_private = false)
|
170
|
-
Actions.constants.each do |constant|
|
171
|
-
mod = Actions.const_get(constant)
|
172
|
-
return true if mod.respond_to?(method_name)
|
173
|
-
end
|
174
|
-
|
175
|
-
super
|
176
|
-
end
|
177
80
|
end
|
178
81
|
end
|
179
82
|
end
|
@@ -2,18 +2,15 @@
|
|
2
2
|
|
3
3
|
module OpenHAB
|
4
4
|
module Core
|
5
|
-
module
|
5
|
+
module DTO
|
6
6
|
java_import org.openhab.core.thing.link.dto.ItemChannelLinkDTO
|
7
7
|
|
8
|
-
# Strictly speaking this class isn't an event, but it's accessed from an AbstractItemChannelLinkEvent
|
9
|
-
|
10
8
|
# Adds methods to core openHAB ItemChannelLinkDTO to make it more natural in Ruby
|
11
9
|
class ItemChannelLinkDTO
|
12
10
|
#
|
13
11
|
# @!attribute [r] item_name
|
14
12
|
# @return [String] The name of the item that was linked or unlinked.
|
15
13
|
#
|
16
|
-
alias_method :item_name, :itemName
|
17
14
|
|
18
15
|
#
|
19
16
|
# @!attribute [r] item
|
@@ -2,26 +2,24 @@
|
|
2
2
|
|
3
3
|
module OpenHAB
|
4
4
|
module Core
|
5
|
-
module
|
5
|
+
module DTO
|
6
6
|
java_import org.openhab.core.thing.dto.AbstractThingDTO
|
7
7
|
|
8
|
-
# Strictly speaking this class isn't an event, but it's accessed from an AbstractThingRegistryEvent
|
9
|
-
|
10
8
|
# Adds methods to core openHAB AbstractThingDTO to make it more natural in Ruby
|
11
9
|
class AbstractThingDTO
|
12
|
-
# @!
|
13
|
-
#
|
14
|
-
#
|
10
|
+
# @!attribute [r] uid
|
11
|
+
# The thing's UID
|
12
|
+
# @return [String]
|
15
13
|
alias_method :uid, :UID
|
16
14
|
|
17
|
-
# @!
|
18
|
-
#
|
19
|
-
#
|
15
|
+
# @!attribute [r] thing_type_uid
|
16
|
+
# The thing type's UID
|
17
|
+
# @return [String]
|
20
18
|
alias_method :thing_type_uid, :thingTypeUID
|
21
19
|
|
22
|
-
# @!
|
23
|
-
#
|
24
|
-
#
|
20
|
+
# @!attribute [r] bridge_uid
|
21
|
+
# The Bridge's UID
|
22
|
+
# @return [String, nil]
|
25
23
|
alias_method :bridge_uid, :bridgeUID
|
26
24
|
end
|
27
25
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
# Contains data transfer objects that represent other openHAB objects
|
6
|
+
# when they need to be represented with simple classes, such as for JSON
|
7
|
+
# responses, or when being attached to events sent over the event bus.
|
8
|
+
module DTO
|
9
|
+
end
|
10
|
+
end
|
11
|
+
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.items.events.AbstractItemRegistryEvent,
|
7
|
+
org.openhab.core.items.events.ItemAddedEvent,
|
8
|
+
org.openhab.core.items.events.ItemUpdatedEvent,
|
9
|
+
org.openhab.core.items.events.ItemRemovedEvent
|
10
|
+
|
11
|
+
#
|
12
|
+
# The {AbstractEvent} sent when an {Item} is added, updated, or removed
|
13
|
+
# from its registry.
|
14
|
+
#
|
15
|
+
# @!attribute [r] item
|
16
|
+
# @return [DTO::ItemDTO] The item that triggered this event.
|
17
|
+
#
|
18
|
+
class AbstractItemRegistryEvent < AbstractEvent; end
|
19
|
+
|
20
|
+
#
|
21
|
+
# The {AbstractEvent} sent with an `item_added` trigger.
|
22
|
+
#
|
23
|
+
class ItemAddedEvent < AbstractItemRegistryEvent; end
|
24
|
+
|
25
|
+
#
|
26
|
+
# The {AbstractEvent} sent with an `item_updated` trigger.
|
27
|
+
#
|
28
|
+
class ItemUpdatedEvent < AbstractItemRegistryEvent; end
|
29
|
+
|
30
|
+
#
|
31
|
+
# The {AbstractEvent} sent with an `item_removed` trigger.
|
32
|
+
#
|
33
|
+
class ItemRemovedEvent < AbstractItemRegistryEvent; end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Events
|
6
|
+
java_import org.openhab.core.thing.events.AbstractThingRegistryEvent,
|
7
|
+
org.openhab.core.thing.events.ThingAddedEvent,
|
8
|
+
org.openhab.core.thing.events.ThingUpdatedEvent,
|
9
|
+
org.openhab.core.thing.events.ThingRemovedEvent
|
10
|
+
|
11
|
+
#
|
12
|
+
# The {AbstractEvent} sent when a {Things::Thing Thing} is added,
|
13
|
+
# updated, or removed from its registry.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# @!attribute [r] thing
|
17
|
+
# @return [DTO::AbstractThingDTO] The thing that triggered this event.
|
18
|
+
#
|
19
|
+
class AbstractThingRegistryEvent < AbstractEvent; end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The {AbstractEvent} sent with a
|
23
|
+
# {DSL::Rules::BuilderDSL#thing_added thing_added trigger}.
|
24
|
+
#
|
25
|
+
class ThingAddedEvent < AbstractThingRegistryEvent; end
|
26
|
+
|
27
|
+
#
|
28
|
+
# The {AbstractEvent} sent with a
|
29
|
+
# {DSL::Rules::BuilderDSL#thing_updated thing_updated trigger}.
|
30
|
+
#
|
31
|
+
class ThingUpdatedEvent < AbstractThingRegistryEvent; end
|
32
|
+
|
33
|
+
#
|
34
|
+
# The {AbstractEvent} sent with a
|
35
|
+
# {DSL::Rules::BuilderDSL#thing_removed thing_removed trigger}.
|
36
|
+
#
|
37
|
+
class ThingRemovedEvent < AbstractThingRegistryEvent; end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|