openhab-scripting 4.46.2 → 5.0.0
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/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 +82 -0
- data/lib/openhab/core/dependency_tracking.rb +34 -0
- data/lib/openhab/core/dto/item_channel_link.rb +33 -0
- data/lib/openhab/core/dto/thing.rb +27 -0
- data/lib/openhab/core/dto.rb +11 -0
- data/lib/openhab/core/entity_lookup.rb +152 -70
- data/lib/openhab/core/events/abstract_event.rb +18 -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 +78 -0
- data/lib/openhab/core/events/item_event.rb +22 -0
- data/lib/openhab/core/events/item_state_changed_event.rb +75 -0
- data/lib/openhab/core/events/item_state_event.rb +79 -0
- data/lib/openhab/core/events/thing_status_info_event.rb +55 -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 +59 -0
- data/lib/openhab/core/items/dimmer_item.rb +148 -0
- data/lib/openhab/core/items/generic_item.rb +292 -0
- data/lib/openhab/core/items/group_item.rb +176 -0
- data/lib/openhab/{dsl → core}/items/image_item.rb +35 -29
- data/lib/openhab/core/items/item.rb +273 -0
- data/lib/openhab/core/items/location_item.rb +34 -0
- data/lib/openhab/core/items/metadata/hash.rb +433 -0
- data/lib/openhab/core/items/metadata/namespace_hash.rb +475 -0
- data/lib/openhab/core/items/metadata/provider.rb +48 -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 +416 -0
- data/lib/openhab/core/items/player_item.rb +66 -0
- data/lib/openhab/core/items/provider.rb +44 -0
- data/lib/openhab/core/items/proxy.rb +136 -0
- data/lib/openhab/core/items/registry.rb +86 -0
- data/lib/openhab/core/items/rollershutter_item.rb +68 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +177 -0
- data/lib/openhab/core/items/semantics.rb +473 -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 +108 -0
- data/lib/openhab/{dsl → core}/lazy_array.rb +9 -3
- data/lib/openhab/core/profile_factory.rb +132 -0
- data/lib/openhab/core/provider.rb +230 -0
- data/lib/openhab/core/proxy.rb +130 -0
- data/lib/openhab/core/registry.rb +40 -0
- data/lib/openhab/core/rules/module.rb +26 -0
- data/lib/openhab/core/rules/provider.rb +25 -0
- data/lib/openhab/core/rules/registry.rb +76 -0
- data/lib/openhab/core/rules/rule.rb +150 -0
- data/lib/openhab/core/rules.rb +25 -0
- data/lib/openhab/core/script_handling.rb +78 -20
- 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/links/provider.rb +78 -0
- data/lib/openhab/core/things/profile_callback.rb +52 -0
- data/lib/openhab/core/things/provider.rb +29 -0
- data/lib/openhab/core/things/proxy.rb +87 -0
- data/lib/openhab/core/things/registry.rb +73 -0
- data/lib/openhab/core/things/thing.rb +194 -0
- data/lib/openhab/core/things.rb +22 -0
- data/lib/openhab/core/timer.rb +148 -0
- data/lib/openhab/{dsl → core}/types/comparable_type.rb +5 -3
- data/lib/openhab/{dsl → core}/types/date_time_type.rb +55 -127
- data/lib/openhab/{dsl → core}/types/decimal_type.rb +50 -48
- data/lib/openhab/{dsl → core}/types/hsb_type.rb +35 -83
- 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/{dsl → core}/types/numeric_type.rb +20 -7
- 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/{dsl → core}/types/percent_type.rb +19 -20
- 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 +325 -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/{dsl → core}/types/string_type.rb +17 -28
- data/lib/openhab/{dsl → core}/types/type.rb +42 -40
- 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 +82 -0
- data/lib/openhab/{dsl → core}/uid.rb +4 -23
- data/lib/openhab/core/value_cache.rb +188 -0
- data/lib/openhab/core.rb +98 -0
- data/lib/openhab/core_ext/between.rb +32 -0
- data/lib/openhab/core_ext/ephemeris.rb +53 -0
- data/lib/openhab/core_ext/java/class.rb +34 -0
- data/lib/openhab/core_ext/java/duration.rb +142 -0
- data/lib/openhab/core_ext/java/list.rb +436 -0
- data/lib/openhab/core_ext/java/local_date.rb +104 -0
- data/lib/openhab/core_ext/java/local_time.rb +118 -0
- data/lib/openhab/core_ext/java/map.rb +66 -0
- data/lib/openhab/core_ext/java/month.rb +71 -0
- data/lib/openhab/core_ext/java/month_day.rb +119 -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 +62 -0
- data/lib/openhab/core_ext/java/unit.rb +15 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +213 -0
- data/lib/openhab/core_ext/ruby/array.rb +21 -0
- data/lib/openhab/core_ext/ruby/date.rb +96 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +55 -0
- data/lib/openhab/core_ext/ruby/module.rb +15 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +195 -0
- data/lib/openhab/core_ext/ruby/range.rb +70 -0
- data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
- data/lib/openhab/core_ext/ruby/time.rb +108 -0
- data/lib/openhab/core_ext.rb +18 -0
- data/lib/openhab/dsl/debouncer.rb +259 -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 +1 -1
- data/lib/openhab/dsl/items/builder.rb +578 -0
- data/lib/openhab/dsl/items/ensure.rb +73 -82
- data/lib/openhab/dsl/items/timed_command.rb +214 -159
- data/lib/openhab/dsl/rules/automation_rule.rb +126 -115
- data/lib/openhab/dsl/rules/builder.rb +1935 -0
- data/lib/openhab/dsl/rules/guard.rb +51 -114
- data/lib/openhab/dsl/rules/name_inference.rb +66 -25
- data/lib/openhab/dsl/rules/property.rb +48 -75
- data/lib/openhab/dsl/rules/rule_triggers.rb +22 -27
- data/lib/openhab/dsl/rules/terse.rb +58 -14
- data/lib/openhab/dsl/rules/triggers/changed.rb +48 -94
- data/lib/openhab/dsl/rules/triggers/channel.rb +9 -40
- data/lib/openhab/dsl/rules/triggers/command.rb +14 -63
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +34 -69
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +6 -14
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +48 -82
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +30 -47
- data/lib/openhab/dsl/rules/triggers/trigger.rb +7 -28
- data/lib/openhab/dsl/rules/triggers/updated.rb +21 -45
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +257 -102
- data/lib/openhab/dsl/rules/triggers.rb +12 -0
- data/lib/openhab/dsl/rules.rb +8 -0
- data/lib/openhab/dsl/things/builder.rb +299 -0
- data/lib/openhab/{core → dsl}/thread_local.rb +27 -17
- data/lib/openhab/dsl/timer_manager.rb +204 -0
- data/lib/openhab/dsl/version.rb +9 -0
- data/lib/openhab/dsl.rb +979 -0
- data/lib/openhab/log.rb +355 -0
- data/lib/openhab/osgi.rb +68 -0
- data/lib/openhab/rspec/configuration.rb +56 -0
- data/lib/openhab/rspec/example_group.rb +132 -0
- data/lib/openhab/rspec/helpers.rb +458 -0
- data/lib/openhab/rspec/hooks.rb +113 -0
- data/lib/openhab/rspec/jruby.rb +46 -0
- data/lib/openhab/rspec/karaf.rb +851 -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/instance_method_stasher.rb +22 -0
- data/lib/openhab/rspec/mocks/persistence_service.rb +155 -0
- data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
- data/lib/openhab/rspec/mocks/space.rb +23 -0
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +63 -0
- data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
- data/lib/openhab/rspec/mocks/timer.rb +134 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +38 -0
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +15 -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 +50 -0
- data/lib/openhab/rspec.rb +26 -0
- data/lib/openhab/yard/base_helper.rb +19 -0
- data/lib/openhab/yard/cli/stats.rb +23 -0
- data/lib/openhab/yard/code_objects/group_object.rb +23 -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/coderay.rb +17 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +58 -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 +30 -0
- data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
- data/lib/openhab/yard/html_helper.rb +78 -0
- data/lib/openhab/yard/markdown_helper.rb +148 -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 +38 -0
- metadata +475 -106
- data/lib/openhab/core/item_proxy.rb +0 -29
- data/lib/openhab/core/load_path.rb +0 -19
- data/lib/openhab/core/openhab_setup.rb +0 -29
- data/lib/openhab/core/osgi.rb +0 -58
- data/lib/openhab/core/services.rb +0 -24
- data/lib/openhab/dsl/actions.rb +0 -114
- data/lib/openhab/dsl/between.rb +0 -25
- data/lib/openhab/dsl/channel.rb +0 -43
- data/lib/openhab/dsl/dsl.rb +0 -59
- data/lib/openhab/dsl/group.rb +0 -54
- data/lib/openhab/dsl/imports.rb +0 -21
- data/lib/openhab/dsl/items/color_item.rb +0 -76
- data/lib/openhab/dsl/items/comparable_item.rb +0 -62
- data/lib/openhab/dsl/items/contact_item.rb +0 -41
- data/lib/openhab/dsl/items/date_time_item.rb +0 -65
- data/lib/openhab/dsl/items/dimmer_item.rb +0 -65
- data/lib/openhab/dsl/items/generic_item.rb +0 -229
- data/lib/openhab/dsl/items/group_item.rb +0 -127
- data/lib/openhab/dsl/items/item_equality.rb +0 -59
- data/lib/openhab/dsl/items/item_registry.rb +0 -54
- data/lib/openhab/dsl/items/items.rb +0 -109
- data/lib/openhab/dsl/items/location_item.rb +0 -59
- data/lib/openhab/dsl/items/metadata.rb +0 -326
- data/lib/openhab/dsl/items/number_item.rb +0 -17
- data/lib/openhab/dsl/items/numeric_item.rb +0 -87
- data/lib/openhab/dsl/items/persistence.rb +0 -307
- data/lib/openhab/dsl/items/player_item.rb +0 -58
- data/lib/openhab/dsl/items/rollershutter_item.rb +0 -51
- data/lib/openhab/dsl/items/semantics/enumerable.rb +0 -91
- data/lib/openhab/dsl/items/semantics.rb +0 -227
- data/lib/openhab/dsl/items/string_item.rb +0 -51
- data/lib/openhab/dsl/items/switch_item.rb +0 -70
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +0 -39
- data/lib/openhab/dsl/monkey_patch/events/events.rb +0 -7
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +0 -85
- data/lib/openhab/dsl/monkey_patch/events/item_event.rb +0 -28
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +0 -61
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +0 -60
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +0 -33
- data/lib/openhab/dsl/monkey_patch/java/java.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/java/local_time.rb +0 -44
- data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +0 -50
- data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +0 -45
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -104
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -6
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +0 -47
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -61
- data/lib/openhab/dsl/openhab.rb +0 -30
- data/lib/openhab/dsl/persistence.rb +0 -27
- data/lib/openhab/dsl/rules/item_event.rb +0 -19
- data/lib/openhab/dsl/rules/rule.rb +0 -160
- data/lib/openhab/dsl/rules/rule_config.rb +0 -147
- data/lib/openhab/dsl/rules/triggers/generic.rb +0 -31
- data/lib/openhab/dsl/rules/triggers/triggers.rb +0 -11
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +0 -81
- data/lib/openhab/dsl/states.rb +0 -89
- data/lib/openhab/dsl/things.rb +0 -147
- data/lib/openhab/dsl/time/month_day.rb +0 -180
- data/lib/openhab/dsl/time/time_of_day.rb +0 -235
- data/lib/openhab/dsl/timers/manager.rb +0 -119
- data/lib/openhab/dsl/timers/reentrant_timer.rb +0 -38
- data/lib/openhab/dsl/timers/timer.rb +0 -132
- data/lib/openhab/dsl/timers.rb +0 -77
- data/lib/openhab/dsl/types/increase_decrease_type.rb +0 -23
- data/lib/openhab/dsl/types/next_previous_type.rb +0 -23
- data/lib/openhab/dsl/types/on_off_type.rb +0 -28
- data/lib/openhab/dsl/types/open_closed_type.rb +0 -29
- data/lib/openhab/dsl/types/play_pause_type.rb +0 -27
- data/lib/openhab/dsl/types/point_type.rb +0 -180
- data/lib/openhab/dsl/types/quantity_type.rb +0 -265
- data/lib/openhab/dsl/types/refresh_type.rb +0 -18
- data/lib/openhab/dsl/types/rewind_fastforward_type.rb +0 -33
- data/lib/openhab/dsl/types/stop_move_type.rb +0 -23
- data/lib/openhab/dsl/types/types.rb +0 -83
- data/lib/openhab/dsl/types/un_def_type.rb +0 -22
- data/lib/openhab/dsl/types/up_down_type.rb +0 -32
- data/lib/openhab/dsl/units.rb +0 -45
- data/lib/openhab/log/configuration.rb +0 -21
- data/lib/openhab/log/logger.rb +0 -282
- data/lib/openhab/version.rb +0 -9
- data/lib/openhab.rb +0 -36
|
@@ -1,134 +1,71 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'openhab/dsl/rules/property'
|
|
4
|
-
require 'openhab/log/logger'
|
|
5
|
-
|
|
6
3
|
module OpenHAB
|
|
7
4
|
module DSL
|
|
8
5
|
module Rules
|
|
9
6
|
#
|
|
10
|
-
#
|
|
7
|
+
# Guard that can prevent execution of a rule if not satisfied
|
|
11
8
|
#
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
# @!visibility private
|
|
10
|
+
class Guard
|
|
11
|
+
#
|
|
12
|
+
# Create a new Guard
|
|
13
|
+
#
|
|
14
|
+
# @param [Array<Proc>] only_if Array of Procs to use as guard
|
|
15
|
+
# @param [Array<Proc>] not_if Array of Procs to use as guard
|
|
16
|
+
#
|
|
17
|
+
def initialize(run_context:, only_if: nil, not_if: nil)
|
|
18
|
+
@run_context = run_context
|
|
19
|
+
@only_if = only_if
|
|
20
|
+
@not_if = not_if
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
#
|
|
24
|
+
# Convert the guard into a string
|
|
25
|
+
#
|
|
26
|
+
# @return [String] describing the only_of and not_if guards
|
|
27
|
+
#
|
|
28
|
+
def to_s
|
|
29
|
+
"only_if: #{@only_if}, not_if: #{@not_if}"
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
#
|
|
28
|
-
#
|
|
33
|
+
# Checks if a guard should run
|
|
29
34
|
#
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
def initialize(run_context:, only_if: nil, not_if: nil)
|
|
40
|
-
@run_context = run_context
|
|
41
|
-
@only_if = only_if
|
|
42
|
-
@not_if = not_if
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
# Convert the guard into a string
|
|
47
|
-
#
|
|
48
|
-
# @return [String] describing the only_of and not_if guards
|
|
49
|
-
#
|
|
50
|
-
def to_s
|
|
51
|
-
"only_if: #{@only_if}, not_if: #{@not_if}"
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
# Checks if a guard should run
|
|
56
|
-
#
|
|
57
|
-
# @param [OpenHAB Trigger Event] event OpenHAB Trigger Event
|
|
58
|
-
#
|
|
59
|
-
# @return [Boolean] True if guard is satisfied, false otherwise
|
|
60
|
-
#
|
|
61
|
-
def should_run?(event)
|
|
62
|
-
logger.trace("Checking guards #{self}")
|
|
63
|
-
check(@only_if, :check_type => :only_if,
|
|
64
|
-
:event => event) && check(@not_if, :check_type => :not_if, :event => event)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
private
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
# Check if guard is satisfied
|
|
71
|
-
#
|
|
72
|
-
# @param [Array] conditions to check
|
|
73
|
-
# @param [Symbol] check_type type of check to perform (:only_if or :not_if)
|
|
74
|
-
# @param [Event] event OpenHAB event to see if it satisfies the guard
|
|
75
|
-
#
|
|
76
|
-
# @return [Boolean] True if guard is satisfied, false otherwise
|
|
77
|
-
#
|
|
78
|
-
def check(conditions, check_type:, event:)
|
|
79
|
-
return true if conditions.nil? || conditions.empty?
|
|
80
|
-
|
|
81
|
-
procs, items = conditions.flatten.partition { |condition| condition.is_a? Proc }
|
|
82
|
-
logger.trace("Procs: #{procs} Items: #{items}")
|
|
83
|
-
|
|
84
|
-
items.each { |item| logger.trace { "#{item} truthy? #{item.truthy?}" } }
|
|
35
|
+
# @param [Object] event openHAB Trigger Event
|
|
36
|
+
#
|
|
37
|
+
# @return [true,false] True if guard is satisfied, false otherwise
|
|
38
|
+
#
|
|
39
|
+
def should_run?(event)
|
|
40
|
+
logger.trace("Checking guards #{self}")
|
|
41
|
+
return false unless check_only_if(event)
|
|
42
|
+
return false unless check_not_if(event)
|
|
85
43
|
|
|
86
|
-
|
|
87
|
-
|
|
44
|
+
true
|
|
45
|
+
end
|
|
88
46
|
|
|
89
|
-
|
|
90
|
-
# Execute the guard check
|
|
91
|
-
#
|
|
92
|
-
# @param [Symbol] check_type :only_if or :not_if to check
|
|
93
|
-
# @param [OpenHAB Event] event event to check if meets guard
|
|
94
|
-
# @param [Array<Item>] items to check if satisfy criteria
|
|
95
|
-
# @param [Array] procs to check if satisfy criteria
|
|
96
|
-
#
|
|
97
|
-
# @return [Boolean] True if criteria are satisfied, false otherwise
|
|
98
|
-
#
|
|
99
|
-
def process_check(check_type:, event:, items:, procs:)
|
|
100
|
-
case check_type
|
|
101
|
-
when :only_if then process_only_if(event, items, procs)
|
|
102
|
-
when :not_if then process_not_if(event, items, procs)
|
|
103
|
-
else raise ArgumentError, "Unexpected check type: #{check_type}"
|
|
104
|
-
end
|
|
105
|
-
end
|
|
47
|
+
private
|
|
106
48
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
items.flatten.none?(&:truthy?) && procs.none? { |proc| @run_context.instance_exec(event, &proc) }
|
|
118
|
-
end
|
|
49
|
+
#
|
|
50
|
+
# Check not_if guards
|
|
51
|
+
#
|
|
52
|
+
# @param [Object] event to check if meets guard
|
|
53
|
+
#
|
|
54
|
+
# @return [true,false] True if criteria are satisfied, false otherwise
|
|
55
|
+
#
|
|
56
|
+
def check_not_if(event)
|
|
57
|
+
@not_if.nil? || @not_if.none? { |proc| @run_context.instance_exec(event, &proc) }
|
|
58
|
+
end
|
|
119
59
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def process_only_if(event, items, procs)
|
|
130
|
-
items.flatten.all?(&:truthy?) && procs.all? { |proc| @run_context.instance_exec(event, &proc) }
|
|
131
|
-
end
|
|
60
|
+
#
|
|
61
|
+
# Check only_if guards
|
|
62
|
+
#
|
|
63
|
+
# @param [Object] event to check if meets guard
|
|
64
|
+
#
|
|
65
|
+
# @return [true,false] True if criteria are satisfied, false otherwise
|
|
66
|
+
#
|
|
67
|
+
def check_only_if(event)
|
|
68
|
+
@only_if.nil? || @only_if.all? { |proc| @run_context.instance_exec(event, &proc) }
|
|
132
69
|
end
|
|
133
70
|
end
|
|
134
71
|
end
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "triggers/cron/cron"
|
|
4
|
+
|
|
3
5
|
module OpenHAB
|
|
4
6
|
module DSL
|
|
5
7
|
module Rules
|
|
6
8
|
# Contains helper methods for inferring a rule name from its triggers
|
|
9
|
+
# @!visibility private
|
|
7
10
|
module NameInference
|
|
8
11
|
# Trigger Type UIDs that we know how to generate a name for
|
|
9
12
|
KNOWN_TRIGGER_TYPES = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"core.ChannelEventTrigger",
|
|
14
|
+
"core.GenericEventTrigger",
|
|
15
|
+
"core.GroupCommandTrigger",
|
|
16
|
+
"core.GroupStateChangeTrigger",
|
|
17
|
+
"core.GroupStateUpdateTrigger",
|
|
18
|
+
"core.ItemCommandTrigger",
|
|
19
|
+
"core.ItemStateChangeTrigger",
|
|
20
|
+
"core.ItemStateUpdateTrigger",
|
|
21
|
+
"core.SystemStartlevelTrigger",
|
|
17
22
|
Triggers::Cron::CRON_TRIGGER_MODULE_ID
|
|
18
23
|
].freeze
|
|
19
24
|
private_constant :KNOWN_TRIGGER_TYPES
|
|
@@ -26,13 +31,13 @@ module OpenHAB
|
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
# formulate a readable rule name such as "TestSwitch received command ON" if possible
|
|
29
|
-
def infer_rule_name(config)
|
|
34
|
+
def infer_rule_name(config)
|
|
30
35
|
known_triggers, unknown_triggers = config.triggers.partition do |t|
|
|
31
36
|
KNOWN_TRIGGER_TYPES.include?(t.type_uid)
|
|
32
37
|
end
|
|
33
38
|
return nil unless unknown_triggers.empty?
|
|
34
39
|
|
|
35
|
-
cron_triggers = known_triggers.select { |t| t.type_uid ==
|
|
40
|
+
cron_triggers = known_triggers.select { |t| t.type_uid == "jsr223.jruby.CronTrigger" }
|
|
36
41
|
ruby_every_triggers = config.ruby_triggers.select { |t| t.first == :every }
|
|
37
42
|
|
|
38
43
|
# makes sure there aren't any true cron triggers cause we can't format them
|
|
@@ -45,7 +50,7 @@ module OpenHAB
|
|
|
45
50
|
private
|
|
46
51
|
|
|
47
52
|
# formulate a readable rule name from a single trigger if possible
|
|
48
|
-
def infer_rule_name_from_trigger(trigger, items, kwargs)
|
|
53
|
+
def infer_rule_name_from_trigger(trigger, items = nil, kwargs = {})
|
|
49
54
|
case trigger
|
|
50
55
|
when :every
|
|
51
56
|
infer_rule_name_from_every_trigger(items, **kwargs)
|
|
@@ -53,11 +58,19 @@ module OpenHAB
|
|
|
53
58
|
infer_rule_name_from_channel_trigger(items, **kwargs)
|
|
54
59
|
when :changed, :updated, :received_command
|
|
55
60
|
infer_rule_name_from_item_trigger(trigger, items, kwargs)
|
|
61
|
+
when :channel_linked, :channel_unlinked
|
|
62
|
+
infer_rule_name_from_channel_link_trigger(trigger)
|
|
63
|
+
when :item_added, :item_removed, :item_updated
|
|
64
|
+
infer_rule_name_from_item_registry_trigger(trigger)
|
|
65
|
+
when :thing_added, :thing_removed, :thing_updated
|
|
66
|
+
infer_rule_name_from_thing_trigger(trigger)
|
|
67
|
+
when :on_start
|
|
68
|
+
infer_rule_name_from_on_start_trigger(items)
|
|
56
69
|
end
|
|
57
70
|
end
|
|
58
71
|
|
|
59
72
|
# formulate a readable rule name from an item-type trigger
|
|
60
|
-
def infer_rule_name_from_item_trigger(trigger, items, kwargs)
|
|
73
|
+
def infer_rule_name_from_item_trigger(trigger, items, kwargs)
|
|
61
74
|
kwargs.delete(:command) if kwargs[:command] == [nil]
|
|
62
75
|
return unless items.length <= 3 &&
|
|
63
76
|
(kwargs.keys - %i[from to command duration]).empty?
|
|
@@ -68,15 +81,15 @@ module OpenHAB
|
|
|
68
81
|
v.is_a?(Proc) || v.is_a?(Enumerable)
|
|
69
82
|
end
|
|
70
83
|
|
|
71
|
-
trigger_name = trigger.to_s.tr(
|
|
84
|
+
trigger_name = trigger.to_s.tr("_", " ")
|
|
72
85
|
item_names = items.map do |item|
|
|
73
|
-
if item.is_a?(GroupItem::
|
|
86
|
+
if item.is_a?(GroupItem::Members)
|
|
74
87
|
"#{item.group.name}.members"
|
|
75
88
|
else
|
|
76
89
|
item.name
|
|
77
90
|
end
|
|
78
91
|
end
|
|
79
|
-
name = "#{
|
|
92
|
+
name = "#{format_array(item_names)} #{trigger_name}"
|
|
80
93
|
|
|
81
94
|
name += " from #{format_inspected_array(kwargs[:from])}" if kwargs[:from]
|
|
82
95
|
name += " to #{format_inspected_array(kwargs[:to])}" if kwargs[:to]
|
|
@@ -95,20 +108,48 @@ module OpenHAB
|
|
|
95
108
|
# formulate a readable rule name from a channel trigger
|
|
96
109
|
def infer_rule_name_from_channel_trigger(channels, triggers:)
|
|
97
110
|
triggers = [] if triggers == [nil]
|
|
98
|
-
name = "#{
|
|
111
|
+
name = "#{format_array(channels)} triggered"
|
|
99
112
|
name += " #{format_inspected_array(triggers)}" unless triggers.empty?
|
|
100
113
|
name
|
|
101
114
|
end
|
|
102
115
|
|
|
103
|
-
#
|
|
104
|
-
def
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
# formulate a readable rule name from a channel link trigger
|
|
117
|
+
def infer_rule_name_from_channel_link_trigger(trigger)
|
|
118
|
+
(trigger == :channel_linked) ? "Channel linked to item" : "Channel unlinked from item"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# formulate a readable rule name from an item added/updated/remove trigger
|
|
122
|
+
def infer_rule_name_from_item_registry_trigger(trigger)
|
|
123
|
+
{
|
|
124
|
+
item_added: "Item added",
|
|
125
|
+
item_updated: "Item updated",
|
|
126
|
+
item_removed: "Item removed"
|
|
127
|
+
}[trigger]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# formulate a readable rule name from a thing added/updated/remove trigger
|
|
131
|
+
def infer_rule_name_from_thing_trigger(trigger)
|
|
132
|
+
{
|
|
133
|
+
thing_added: "Thing Added",
|
|
134
|
+
thing_updated: "Thing updated",
|
|
135
|
+
thing_removed: "Thing removed"
|
|
136
|
+
}[trigger]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# formulate a readable rule name from an on_start trigger
|
|
140
|
+
def infer_rule_name_from_on_start_trigger(levels)
|
|
141
|
+
levels = levels.map { |level| "#{level} (#{start_level_description(level)})" }
|
|
142
|
+
levels = format_array(levels)
|
|
143
|
+
"System Start Level reached #{levels}"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def start_level_description(level)
|
|
147
|
+
klass = org.openhab.core.service.StartLevelService.java_class
|
|
148
|
+
start_level_type = klass.declared_field("STARTLEVEL_OSGI").type
|
|
149
|
+
klass.declared_fields
|
|
150
|
+
.select { |field| field.type == start_level_type && field.name.start_with?("STARTLEVEL_") }
|
|
151
|
+
.find { |field| field.get_int(klass) == level }
|
|
152
|
+
.name.split("_", 2).last.downcase
|
|
112
153
|
end
|
|
113
154
|
|
|
114
155
|
# format an array of items that need to be inspected individually
|
|
@@ -124,7 +165,7 @@ module OpenHAB
|
|
|
124
165
|
return array[0] if array.length == 1
|
|
125
166
|
return "#{array[0]} or #{array[1]}" if array.length == 2
|
|
126
167
|
|
|
127
|
-
"
|
|
168
|
+
"#{array[0..-2].join(", ")}, or #{array[-1]}"
|
|
128
169
|
end
|
|
129
170
|
end
|
|
130
171
|
end
|
|
@@ -1,101 +1,74 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'openhab/log/logger'
|
|
4
|
-
|
|
5
3
|
module OpenHAB
|
|
6
4
|
module DSL
|
|
7
5
|
module Rules
|
|
8
6
|
#
|
|
9
7
|
# Provides methods to support DSL properties
|
|
10
8
|
#
|
|
9
|
+
# @visibility private
|
|
11
10
|
module Property
|
|
12
|
-
include OpenHAB::Log
|
|
13
|
-
|
|
14
11
|
#
|
|
15
|
-
#
|
|
12
|
+
# Dynamically creates a property that acts as an accessor with no arguments
|
|
13
|
+
# and a setter with any number of arguments or a block.
|
|
16
14
|
#
|
|
17
|
-
# @param [
|
|
15
|
+
# @param [String] name of the property
|
|
18
16
|
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
def prop(name)
|
|
18
|
+
# rubocop rules are disabled because this method is dynamically defined on the calling
|
|
19
|
+
# object making calls to other methods in this module impossible, or if done on methods
|
|
20
|
+
# in this module than instance variable belong to the module not the calling class
|
|
21
|
+
define_method(name) do |*args, &block|
|
|
22
|
+
if args.empty? && block.nil? == true
|
|
23
|
+
instance_variable_get("@#{name}")
|
|
24
|
+
else
|
|
25
|
+
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
26
|
+
if args.length == 1
|
|
27
|
+
instance_variable_set("@#{name}", args.first)
|
|
28
|
+
elsif args.length > 1
|
|
29
|
+
instance_variable_set("@#{name}", args)
|
|
30
|
+
elsif block
|
|
31
|
+
instance_variable_set("@#{name}", block)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
22
35
|
end
|
|
23
36
|
|
|
24
37
|
#
|
|
25
|
-
#
|
|
38
|
+
# Dynamically creates a property array that acts as an accessor with no arguments
|
|
39
|
+
# and pushes any number of arguments or a block onto the property array
|
|
40
|
+
# You can provide a block to this method which can be used to check if the provided value is acceptable.
|
|
41
|
+
#
|
|
42
|
+
# @param [String] name of the property
|
|
43
|
+
# @param [String] array_name name of the array to use, defaults to name of property
|
|
44
|
+
# @param [Class] wrapper object to put around elements added to the array
|
|
26
45
|
#
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# rubocop rules are disabled because this method is dynamically defined on the calling
|
|
41
|
-
# object making calls to other methods in this module impossible, or if done on methods
|
|
42
|
-
# in this module than instance variable belong to the module not the calling class
|
|
43
|
-
define_method(name) do |*args, &block|
|
|
44
|
-
if args.length.zero? && block.nil? == true
|
|
45
|
-
instance_variable_get("@#{name}")
|
|
46
|
-
else
|
|
47
|
-
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
48
|
-
if args.length == 1
|
|
49
|
-
instance_variable_set("@#{name}", args.first)
|
|
50
|
-
elsif args.length > 1
|
|
51
|
-
instance_variable_set("@#{name}", args)
|
|
52
|
-
elsif block
|
|
53
|
-
instance_variable_set("@#{name}", block)
|
|
54
|
-
end
|
|
46
|
+
def prop_array(name, array_name: nil, wrapper: nil)
|
|
47
|
+
define_method(name) do |*args, &block|
|
|
48
|
+
array_name ||= name
|
|
49
|
+
if args.empty? && block.nil? == true
|
|
50
|
+
instance_variable_get("@#{array_name}")
|
|
51
|
+
else
|
|
52
|
+
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
53
|
+
if args.length == 1
|
|
54
|
+
insert = args.first
|
|
55
|
+
elsif args.length > 1
|
|
56
|
+
insert = args
|
|
57
|
+
elsif block
|
|
58
|
+
insert = block
|
|
55
59
|
end
|
|
60
|
+
yield insert if block_given?
|
|
61
|
+
insert = wrapper.new(insert) if wrapper
|
|
62
|
+
instance_variable_set("@#{array_name}", (instance_variable_get("@#{array_name}") || []) << insert)
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
# Dynamically creates a property array acts and an accessor with no arguments
|
|
61
|
-
# and a pushes any number of arguments or a block onto they property array
|
|
62
|
-
# You can provide a block to this method which can be used to check if the provided value is acceptable.
|
|
63
|
-
#
|
|
64
|
-
# @param [String] name of the property
|
|
65
|
-
# @param [String] array_name name of the array to use, defaults to name of property
|
|
66
|
-
# @param [Class] wrapper object to put around elements added to the array
|
|
67
|
-
#
|
|
68
|
-
def prop_array(name, array_name: nil, wrapper: nil)
|
|
69
|
-
define_method(name) do |*args, &block|
|
|
70
|
-
array_name ||= name
|
|
71
|
-
if args.length.zero? && block.nil? == true
|
|
72
|
-
instance_variable_get("@#{array_name}")
|
|
73
|
-
else
|
|
74
|
-
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
75
|
-
if args.length == 1
|
|
76
|
-
insert = args.first
|
|
77
|
-
elsif args.length > 1
|
|
78
|
-
insert = args
|
|
79
|
-
elsif block
|
|
80
|
-
insert = block
|
|
81
|
-
end
|
|
82
|
-
yield insert if block_given?
|
|
83
|
-
insert = wrapper.new(insert) if wrapper
|
|
84
|
-
instance_variable_set("@#{array_name}", (instance_variable_get("@#{array_name}") || []) << insert)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
return unless array_name
|
|
66
|
+
return unless array_name
|
|
89
67
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
68
|
+
define_method(array_name) do
|
|
69
|
+
instance_variable_get("@#{array_name}")
|
|
93
70
|
end
|
|
94
71
|
end
|
|
95
|
-
# rubocop:enable Metrics/MethodLength
|
|
96
|
-
# rubocop:enable Metrics/AbcSize
|
|
97
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
98
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
99
72
|
end
|
|
100
73
|
end
|
|
101
74
|
end
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
|
|
5
|
-
require
|
|
6
|
-
|
|
7
|
-
require_relative
|
|
3
|
+
require "forwardable"
|
|
4
|
+
|
|
5
|
+
require "securerandom"
|
|
6
|
+
|
|
7
|
+
require_relative "triggers/conditions/proc"
|
|
8
8
|
|
|
9
9
|
module OpenHAB
|
|
10
10
|
module DSL
|
|
11
|
-
#
|
|
12
|
-
# Creates and manages OpenHAB Rules
|
|
13
|
-
#
|
|
14
11
|
module Rules
|
|
15
12
|
#
|
|
16
|
-
# Rule configuration for
|
|
13
|
+
# Rule configuration for openHAB Rules engine
|
|
17
14
|
#
|
|
15
|
+
# @!visibility private
|
|
18
16
|
class RuleTriggers
|
|
19
|
-
include OpenHAB::Log
|
|
20
|
-
|
|
21
|
-
java_import org.openhab.core.automation.util.TriggerBuilder
|
|
22
|
-
java_import org.openhab.core.config.core.Configuration
|
|
23
|
-
|
|
24
17
|
# @return [Array] Of triggers
|
|
25
18
|
attr_accessor :triggers
|
|
26
19
|
|
|
@@ -35,7 +28,7 @@ module OpenHAB
|
|
|
35
28
|
#
|
|
36
29
|
def initialize
|
|
37
30
|
@triggers = []
|
|
38
|
-
@trigger_conditions = Hash.new(
|
|
31
|
+
@trigger_conditions = Hash.new(Triggers::Conditions::Proc::ANY)
|
|
39
32
|
@attachments = {}
|
|
40
33
|
end
|
|
41
34
|
|
|
@@ -46,12 +39,12 @@ module OpenHAB
|
|
|
46
39
|
# @param [Map] config map describing trigger configuration
|
|
47
40
|
# @param [Object] attach object to be attached to the trigger
|
|
48
41
|
#
|
|
49
|
-
# @return [Trigger]
|
|
42
|
+
# @return [org.openhab.core.automation.Trigger] openHAB trigger
|
|
50
43
|
#
|
|
51
44
|
def append_trigger(type:, config:, attach: nil, conditions: nil)
|
|
52
45
|
config.transform_keys!(&:to_s)
|
|
53
46
|
RuleTriggers.trigger(type: type, config: config).tap do |trigger|
|
|
54
|
-
logger.trace("Appending trigger (#{trigger}) attach (#{attach}) conditions(#{conditions})")
|
|
47
|
+
logger.trace("Appending trigger (#{trigger.inspect}) attach (#{attach}) conditions(#{conditions})")
|
|
55
48
|
@triggers << trigger
|
|
56
49
|
@attachments[trigger.id] = attach if attach
|
|
57
50
|
@trigger_conditions[trigger.id] = conditions if conditions
|
|
@@ -64,15 +57,15 @@ module OpenHAB
|
|
|
64
57
|
# @param [String] type of trigger
|
|
65
58
|
# @param [Map] config map
|
|
66
59
|
#
|
|
67
|
-
# @return [
|
|
60
|
+
# @return [org.openhab.core.automation.Trigger] configured by type and supplied config
|
|
68
61
|
#
|
|
69
62
|
def self.trigger(type:, config:)
|
|
70
63
|
logger.trace("Creating trigger of type '#{type}' config: #{config}")
|
|
71
|
-
TriggerBuilder.create
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
org.openhab.core.automation.util.TriggerBuilder.create
|
|
65
|
+
.with_id(uuid)
|
|
66
|
+
.with_type_uid(type)
|
|
67
|
+
.with_configuration(org.openhab.core.config.core.Configuration.new(config))
|
|
68
|
+
.build
|
|
76
69
|
end
|
|
77
70
|
|
|
78
71
|
#
|
|
@@ -90,10 +83,12 @@ module OpenHAB
|
|
|
90
83
|
# @return [String] details of the config object
|
|
91
84
|
#
|
|
92
85
|
def inspect
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
<<~TEXT.tr("\n", " ")
|
|
87
|
+
#<RuleTriggers #{triggers.inspect}
|
|
88
|
+
Conditions: #{trigger_conditions.inspect}
|
|
89
|
+
UIDs: #{triggers.map(&:id).inspect}
|
|
90
|
+
Attachments: #{attachments.inspect}>
|
|
91
|
+
TEXT
|
|
97
92
|
end
|
|
98
93
|
end
|
|
99
94
|
end
|