openhab-scripting 2.16.2 → 2.16.3
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.rb +12 -16
- data/lib/openhab/core/entity_lookup.rb +162 -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 +47 -0
- data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
- data/lib/openhab/dsl/group.rb +100 -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/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 +7 -0
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -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 +8 -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 +228 -0
- data/lib/openhab/dsl/timers.rb +77 -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 +55 -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/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: 2.16.
|
|
4
|
+
version: 2.16.3
|
|
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-02-
|
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -32,62 +32,59 @@ extensions: []
|
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
34
|
- lib/openhab.rb
|
|
35
|
-
- lib/openhab/
|
|
36
|
-
- lib/openhab/core/
|
|
37
|
-
- lib/openhab/core/
|
|
38
|
-
- lib/openhab/
|
|
39
|
-
- lib/openhab/
|
|
40
|
-
- lib/openhab/
|
|
41
|
-
- lib/openhab/
|
|
42
|
-
- lib/openhab/
|
|
43
|
-
- lib/openhab/
|
|
44
|
-
- lib/openhab/
|
|
45
|
-
- lib/openhab/
|
|
46
|
-
- lib/openhab/
|
|
47
|
-
- lib/openhab/
|
|
48
|
-
- lib/openhab/
|
|
49
|
-
- lib/openhab/
|
|
50
|
-
- lib/openhab/
|
|
51
|
-
- lib/openhab/
|
|
52
|
-
- lib/openhab/
|
|
53
|
-
- lib/openhab/
|
|
54
|
-
- lib/openhab/
|
|
55
|
-
- lib/openhab/
|
|
56
|
-
- lib/openhab/
|
|
57
|
-
- lib/openhab/
|
|
58
|
-
- lib/openhab/
|
|
59
|
-
- lib/openhab/
|
|
60
|
-
- lib/openhab/
|
|
61
|
-
- lib/openhab/
|
|
62
|
-
- lib/openhab/
|
|
63
|
-
- lib/openhab/
|
|
64
|
-
- lib/openhab/
|
|
65
|
-
- lib/openhab/
|
|
66
|
-
- lib/openhab/
|
|
67
|
-
- lib/openhab/
|
|
68
|
-
- lib/openhab/
|
|
69
|
-
- lib/openhab/
|
|
70
|
-
- lib/openhab/
|
|
71
|
-
- lib/openhab/
|
|
72
|
-
- lib/openhab/
|
|
73
|
-
- lib/openhab/
|
|
74
|
-
- lib/openhab/
|
|
75
|
-
- lib/openhab/
|
|
76
|
-
- lib/openhab/
|
|
77
|
-
- lib/openhab/
|
|
78
|
-
- lib/openhab/
|
|
79
|
-
- lib/openhab/
|
|
80
|
-
- lib/openhab/
|
|
81
|
-
- lib/openhab/
|
|
82
|
-
- lib/openhab/
|
|
83
|
-
- lib/openhab/
|
|
84
|
-
- lib/openhab/
|
|
85
|
-
- lib/openhab/
|
|
86
|
-
- lib/openhab/
|
|
87
|
-
- lib/openhab/
|
|
88
|
-
- lib/openhab/core/patch_load_path.rb
|
|
89
|
-
- lib/openhab/core/startup_delay.rb
|
|
90
|
-
- lib/openhab/osgi.rb
|
|
35
|
+
- lib/openhab/core/entity_lookup.rb
|
|
36
|
+
- lib/openhab/core/openhab_setup.rb
|
|
37
|
+
- lib/openhab/core/osgi.rb
|
|
38
|
+
- lib/openhab/dsl/actions.rb
|
|
39
|
+
- lib/openhab/dsl/dsl.rb
|
|
40
|
+
- lib/openhab/dsl/gems.rb
|
|
41
|
+
- lib/openhab/dsl/group.rb
|
|
42
|
+
- lib/openhab/dsl/items/items.rb
|
|
43
|
+
- lib/openhab/dsl/items/number_item.rb
|
|
44
|
+
- lib/openhab/dsl/items/string_item.rb
|
|
45
|
+
- lib/openhab/dsl/monkey_patch/actions/actions.rb
|
|
46
|
+
- lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb
|
|
47
|
+
- lib/openhab/dsl/monkey_patch/events/events.rb
|
|
48
|
+
- lib/openhab/dsl/monkey_patch/events/item_command.rb
|
|
49
|
+
- lib/openhab/dsl/monkey_patch/events/item_state_changed.rb
|
|
50
|
+
- lib/openhab/dsl/monkey_patch/events/thing_status_info.rb
|
|
51
|
+
- lib/openhab/dsl/monkey_patch/items/contact_item.rb
|
|
52
|
+
- lib/openhab/dsl/monkey_patch/items/dimmer_item.rb
|
|
53
|
+
- lib/openhab/dsl/monkey_patch/items/group_item.rb
|
|
54
|
+
- lib/openhab/dsl/monkey_patch/items/items.rb
|
|
55
|
+
- lib/openhab/dsl/monkey_patch/items/metadata.rb
|
|
56
|
+
- lib/openhab/dsl/monkey_patch/items/persistence.rb
|
|
57
|
+
- lib/openhab/dsl/monkey_patch/items/switch_item.rb
|
|
58
|
+
- lib/openhab/dsl/monkey_patch/ruby/number.rb
|
|
59
|
+
- lib/openhab/dsl/monkey_patch/ruby/range.rb
|
|
60
|
+
- lib/openhab/dsl/monkey_patch/ruby/ruby.rb
|
|
61
|
+
- lib/openhab/dsl/monkey_patch/ruby/string.rb
|
|
62
|
+
- lib/openhab/dsl/monkey_patch/types/decimal_type.rb
|
|
63
|
+
- lib/openhab/dsl/monkey_patch/types/on_off_type.rb
|
|
64
|
+
- lib/openhab/dsl/monkey_patch/types/open_closed_type.rb
|
|
65
|
+
- lib/openhab/dsl/monkey_patch/types/percent_type.rb
|
|
66
|
+
- lib/openhab/dsl/monkey_patch/types/quantity_type.rb
|
|
67
|
+
- lib/openhab/dsl/monkey_patch/types/types.rb
|
|
68
|
+
- lib/openhab/dsl/persistence.rb
|
|
69
|
+
- lib/openhab/dsl/rules/automation_rule.rb
|
|
70
|
+
- lib/openhab/dsl/rules/guard.rb
|
|
71
|
+
- lib/openhab/dsl/rules/property.rb
|
|
72
|
+
- lib/openhab/dsl/rules/rule.rb
|
|
73
|
+
- lib/openhab/dsl/rules/rule_config.rb
|
|
74
|
+
- lib/openhab/dsl/rules/triggers/changed.rb
|
|
75
|
+
- lib/openhab/dsl/rules/triggers/channel.rb
|
|
76
|
+
- lib/openhab/dsl/rules/triggers/command.rb
|
|
77
|
+
- lib/openhab/dsl/rules/triggers/cron.rb
|
|
78
|
+
- lib/openhab/dsl/rules/triggers/trigger.rb
|
|
79
|
+
- lib/openhab/dsl/rules/triggers/updated.rb
|
|
80
|
+
- lib/openhab/dsl/states.rb
|
|
81
|
+
- lib/openhab/dsl/things.rb
|
|
82
|
+
- lib/openhab/dsl/time_of_day.rb
|
|
83
|
+
- lib/openhab/dsl/timers.rb
|
|
84
|
+
- lib/openhab/dsl/types/quantity.rb
|
|
85
|
+
- lib/openhab/dsl/units.rb
|
|
86
|
+
- lib/openhab/log/configuration.rb
|
|
87
|
+
- lib/openhab/log/logger.rb
|
|
91
88
|
- lib/openhab/version.rb
|
|
92
89
|
homepage: https://boc-tothefuture.github.io/openhab-jruby/
|
|
93
90
|
licenses: []
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# This module holds global configuration values
|
|
4
|
-
module Configuration
|
|
5
|
-
# -*- coding: utf-8 -*-
|
|
6
|
-
LOG_PREFIX = 'jsr223.jruby'
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
# Gets the log prefix
|
|
10
|
-
#
|
|
11
|
-
# @return [String] Prefix for all log entries
|
|
12
|
-
#
|
|
13
|
-
def self.log_prefix
|
|
14
|
-
LOG_PREFIX
|
|
15
|
-
end
|
|
16
|
-
end
|
data/lib/openhab/core/cron.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OpenHAB
|
|
4
|
-
module Core
|
|
5
|
-
#
|
|
6
|
-
# Module for Cron related methods
|
|
7
|
-
#
|
|
8
|
-
module Cron
|
|
9
|
-
#
|
|
10
|
-
# Retruns a default map for cron expressions that fires every second
|
|
11
|
-
# This map is usually updated via merge by other methods to refine cron type triggers.
|
|
12
|
-
#
|
|
13
|
-
# @return [Map] Map with symbols for :seconds, :minute, :hour, :dom, :month, :dow configured to fire every second
|
|
14
|
-
#
|
|
15
|
-
def cron_expression_map
|
|
16
|
-
{
|
|
17
|
-
second: '*',
|
|
18
|
-
minute: '*',
|
|
19
|
-
hour: '*',
|
|
20
|
-
dom: '?',
|
|
21
|
-
month: '*',
|
|
22
|
-
dow: '?'
|
|
23
|
-
}
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/lib/openhab/core/debug.rb
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'pp'
|
|
4
|
-
require 'core/log'
|
|
5
|
-
require 'core/dsl/things'
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
# Module to support debugging information about the Ruby or OpenHAB environment
|
|
9
|
-
#
|
|
10
|
-
module Debug
|
|
11
|
-
include Logging
|
|
12
|
-
include OpenHAB::Core::DSL::Things
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# Print the loadpath, instance and global variables
|
|
16
|
-
#
|
|
17
|
-
def debug_variables
|
|
18
|
-
pp "Instance #{instance_variables}"
|
|
19
|
-
pp "Global #{global_variables}"
|
|
20
|
-
pp "Load Path #{$LOAD_PATH}"
|
|
21
|
-
# pp "Constants #{Module.constants}"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
#
|
|
25
|
-
# Print information about the OpenHAB instance
|
|
26
|
-
#
|
|
27
|
-
def debug_openhab
|
|
28
|
-
logger.debug { "Things - Count #{things.size}" }
|
|
29
|
-
things.each do |thing|
|
|
30
|
-
logger.debug { "Thing:(#{thing.label}) UID:(#{thing.uid}) Channels(#{thing.channels.map(&:uid).join(', ')})" }
|
|
31
|
-
end
|
|
32
|
-
# logger.debug { $things.getAll.join(", ") }
|
|
33
|
-
end
|
|
34
|
-
end
|
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
|