openhab-scripting 4.47.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/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 -38
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'time_extensions'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
module DSL
|
7
|
-
# monkey patches
|
8
|
-
module MonkeyPatch
|
9
|
-
# extensions to Java objects
|
10
|
-
module JavaExtensions
|
11
|
-
#
|
12
|
-
# Extend LocalTime class to support arithmetic operators
|
13
|
-
#
|
14
|
-
module LocalTimeExtensions
|
15
|
-
include TimeExtensions
|
16
|
-
include OpenHAB::Log
|
17
|
-
|
18
|
-
# apply meta-programming methods to prepending class
|
19
|
-
# @!visibility private
|
20
|
-
def self.prepended(klass)
|
21
|
-
# remove the JRuby default == so that we can inherit the Ruby method
|
22
|
-
klass.remove_method :==
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Comparison
|
27
|
-
#
|
28
|
-
# @param [LocalTime,TimeOfDay] other object to compare to
|
29
|
-
#
|
30
|
-
# @return [Integer] -1, 0, +1 depending on whether +other+ is
|
31
|
-
# less than, equal to, or greater than self
|
32
|
-
#
|
33
|
-
def compare_to(other)
|
34
|
-
logger.trace("(#{self.class}) #{self} compare_to #{other} (#{other.class})")
|
35
|
-
other = other.local_time if other.is_a?(TimeOfDay)
|
36
|
-
super
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
java.time.LocalTime.prepend(OpenHAB::DSL::MonkeyPatch::JavaExtensions::LocalTimeExtensions)
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
# monkey patches
|
6
|
-
module MonkeyPatch
|
7
|
-
# Extensions to Java objects
|
8
|
-
module JavaExtensions
|
9
|
-
# Common extensions to Java date/time classes
|
10
|
-
module TimeExtensions
|
11
|
-
#
|
12
|
-
# Add other TemporalAmount or Duration object
|
13
|
-
#
|
14
|
-
# @param [TemporalAmount] other the TemporalAmount to be added to this ZonedDateTime object
|
15
|
-
#
|
16
|
-
# @return [ZonedDateTime] The resulting ZonedDateTime object after adding {other}
|
17
|
-
#
|
18
|
-
def +(other)
|
19
|
-
plus(other)
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Subtract other TemporalAmount or Duration object
|
24
|
-
#
|
25
|
-
# @param [TemporalAmount] other the TemporalAmount to be subtracted from this ZonedDateTime object
|
26
|
-
#
|
27
|
-
# @return [ZonedDateTime] The resulting ZonedDateTime object after subtracting {other}
|
28
|
-
#
|
29
|
-
def -(other)
|
30
|
-
minus(other)
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Compare against another time object
|
35
|
-
#
|
36
|
-
# @param [Object] other The other time object to compare against.
|
37
|
-
#
|
38
|
-
# @return [Integer] -1, 0, +1 depending on whether +other+ is
|
39
|
-
# less than, equal to, or greater than self
|
40
|
-
#
|
41
|
-
def <=>(other)
|
42
|
-
compare_to(other)
|
43
|
-
rescue StandardError
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'time_extensions'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
module DSL
|
7
|
-
module MonkeyPatch
|
8
|
-
#
|
9
|
-
# Extends the functionalities of Java classes
|
10
|
-
#
|
11
|
-
module JavaExtensions
|
12
|
-
#
|
13
|
-
# Extend ZonedDateTime class to support arithmetic operators
|
14
|
-
#
|
15
|
-
module ZonedDateTimeExtensions
|
16
|
-
include TimeExtensions
|
17
|
-
include OpenHAB::Log
|
18
|
-
|
19
|
-
# apply meta-programming methods to prepending class
|
20
|
-
# @!visibility private
|
21
|
-
def self.prepended(klass)
|
22
|
-
# remove the JRuby default == so that we can inherit the Ruby method
|
23
|
-
klass.remove_method :==
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Comparison
|
28
|
-
#
|
29
|
-
# @param [ZonedDateTime,Time] other object to compare to
|
30
|
-
#
|
31
|
-
# @return [Integer] -1, 0, +1 depending on whether +other+ is
|
32
|
-
# less than, equal to, or greater than self
|
33
|
-
#
|
34
|
-
def compare_to(other)
|
35
|
-
logger.trace("(#{self.class}) #{self} compare_to #{other} (#{other.class})")
|
36
|
-
other = other.to_java(ZonedDateTime) if other.is_a? Time
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
ZonedDateTime.prepend(OpenHAB::DSL::MonkeyPatch::JavaExtensions::ZonedDateTimeExtensions)
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
module MonkeyPatch
|
6
|
-
module Ruby
|
7
|
-
#
|
8
|
-
# Extend integer to create duration object
|
9
|
-
#
|
10
|
-
module IntegerExtensions
|
11
|
-
#
|
12
|
-
# Create Duration with the specified unit
|
13
|
-
#
|
14
|
-
# @return [java.time.Duration] Duration with number of units from self
|
15
|
-
#
|
16
|
-
%w[millis seconds minutes hours].each do |unit|
|
17
|
-
define_method(unit) { java.time.Duration.public_send("of_#{unit}", self) }
|
18
|
-
end
|
19
|
-
|
20
|
-
alias second seconds
|
21
|
-
alias millisecond millis
|
22
|
-
alias milliseconds millis
|
23
|
-
alias ms millis
|
24
|
-
alias minute minutes
|
25
|
-
alias hour hours
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Extend float to create duration object
|
30
|
-
#
|
31
|
-
module FloatExtensions
|
32
|
-
#
|
33
|
-
# Create Duration with number of milliseconds
|
34
|
-
#
|
35
|
-
# @return [java.time.Duration] Duration truncated to an integral number of milliseconds from self
|
36
|
-
#
|
37
|
-
def millis
|
38
|
-
java.time.Duration.of_millis(to_i)
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Create Duration with number of seconds
|
43
|
-
#
|
44
|
-
# @return [java.time.Duration] Duration with number of seconds from self
|
45
|
-
#
|
46
|
-
def seconds
|
47
|
-
(self * 1000).millis
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Create Duration with number of minutes
|
52
|
-
#
|
53
|
-
# @return [java.time.Duration] Duration with number of minutes from self
|
54
|
-
#
|
55
|
-
def minutes
|
56
|
-
(self * 60).seconds
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Create Duration with number of hours
|
61
|
-
#
|
62
|
-
# @return [java.time.Duration] Duration with number of hours from self
|
63
|
-
#
|
64
|
-
def hours
|
65
|
-
(self * 60).minutes
|
66
|
-
end
|
67
|
-
|
68
|
-
alias second seconds
|
69
|
-
alias millisecond millis
|
70
|
-
alias milliseconds millis
|
71
|
-
alias ms millis
|
72
|
-
alias minute minutes
|
73
|
-
alias hour hours
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Extend numeric to create quantity object
|
78
|
-
#
|
79
|
-
module NumericExtensions
|
80
|
-
#
|
81
|
-
# Convert Numeric to a QuantityType
|
82
|
-
#
|
83
|
-
# @param [Object] other String or Unit representing an OpenHAB Unit
|
84
|
-
#
|
85
|
-
# @return [Types::QuantityType] +self+ as a {Types::QuantityType} of the supplied Unit
|
86
|
-
#
|
87
|
-
def |(other)
|
88
|
-
other = org.openhab.core.types.util.UnitUtils.parse_unit(other.to_str) if other.respond_to?(:to_str)
|
89
|
-
|
90
|
-
return super unless other.is_a?(javax.measure.Unit)
|
91
|
-
|
92
|
-
Types::QuantityType.new(to_d.to_java, other)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
Integer.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::IntegerExtensions)
|
101
|
-
Float.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::FloatExtensions)
|
102
|
-
Numeric.include(OpenHAB::DSL::MonkeyPatch::Ruby::NumericExtensions)
|
103
|
-
# Integer already has #|, so we have to prepend it here
|
104
|
-
Integer.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::NumericExtensions)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openhab/dsl/time/time_of_day'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
module DSL
|
7
|
-
# monkey patches
|
8
|
-
module MonkeyPatch
|
9
|
-
# extensions to core Ruby objects
|
10
|
-
module Ruby
|
11
|
-
# extend String class so that it will do semantic comparisons against
|
12
|
-
# DateTimeType and QuantityType, instead of converting the latter to
|
13
|
-
# String and doing an exact match
|
14
|
-
module StringExtensions
|
15
|
-
# {include:StringExtensions}
|
16
|
-
def ==(other)
|
17
|
-
case other
|
18
|
-
when Types::QuantityType,
|
19
|
-
Types::DateTimeType,
|
20
|
-
Items::DateTimeItem,
|
21
|
-
Items::NumericItem,
|
22
|
-
Between::TimeOfDay
|
23
|
-
other == self
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# {include:StringExtensions}
|
30
|
-
def <=>(other)
|
31
|
-
case other
|
32
|
-
when Types::QuantityType,
|
33
|
-
Types::DateTimeType,
|
34
|
-
Items::DateTimeItem,
|
35
|
-
Items::NumericItem
|
36
|
-
(other <=> self)&.-@()
|
37
|
-
else
|
38
|
-
super
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
String.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::StringExtensions)
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
module MonkeyPatch
|
6
|
-
module Ruby
|
7
|
-
# Extend Time class to allow adding/subtracting against Duration
|
8
|
-
module TimeExtensions
|
9
|
-
#
|
10
|
-
# Add time offset
|
11
|
-
#
|
12
|
-
# @param [Numeric,Duration] other The offset to add
|
13
|
-
#
|
14
|
-
# @return [Time] The resulting time after adding the given offset
|
15
|
-
#
|
16
|
-
def +(other)
|
17
|
-
other = to_seconds(other)
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# Subtract time offset
|
23
|
-
#
|
24
|
-
# @param [Numeric,Duration] other The offset to subtract
|
25
|
-
#
|
26
|
-
# @return [Time] The resulting time after subtracting the given offset
|
27
|
-
#
|
28
|
-
def -(other)
|
29
|
-
other = to_seconds(other)
|
30
|
-
super
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Convert to ZonedDateTime
|
35
|
-
#
|
36
|
-
# @return [ZonedDateTime] The current time object converted to ZonedDateTime
|
37
|
-
#
|
38
|
-
def to_zdt
|
39
|
-
to_java(ZonedDateTime)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
#
|
45
|
-
# Convert to floating point seconds if the given value reponds to to_nanos
|
46
|
-
#
|
47
|
-
# @param [Numeric,Duration] value The duration to convert into seconds.
|
48
|
-
#
|
49
|
-
# @return [Numeric] The number of seconds from the given value
|
50
|
-
#
|
51
|
-
def to_seconds(value)
|
52
|
-
value = value.to_nanos.to_f / 1_000_000_000 if value.respond_to? :to_nanos
|
53
|
-
value
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
Time.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::TimeExtensions)
|
data/lib/openhab/dsl/openhab.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
#
|
7
|
-
# Return the OpenHAB conf directory as a ruby pathname
|
8
|
-
#
|
9
|
-
# @return [Pathname] OpenHAB conf path
|
10
|
-
#
|
11
|
-
def self.conf_root
|
12
|
-
Pathname.new(ENV.fetch('OPENHAB_CONF', nil))
|
13
|
-
end
|
14
|
-
|
15
|
-
module DSL
|
16
|
-
#
|
17
|
-
# Provides access to OpenHAB attributes
|
18
|
-
#
|
19
|
-
module Core
|
20
|
-
include OpenHAB::Log
|
21
|
-
|
22
|
-
module_function
|
23
|
-
|
24
|
-
# @deprecated Please use {OpenHAB.conf_root} instead
|
25
|
-
def __conf__
|
26
|
-
OpenHAB.conf_root
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
#
|
6
|
-
# Provides support for interacting with OpenHAB Persistence service
|
7
|
-
#
|
8
|
-
module Persistence
|
9
|
-
module_function
|
10
|
-
|
11
|
-
#
|
12
|
-
# Sets a thread local variable to set the default persistence service
|
13
|
-
# for method calls inside the block
|
14
|
-
#
|
15
|
-
# @param [Object] service service either as a String or a Symbol
|
16
|
-
# @yield [] Block executed in context of the supplied persistence service
|
17
|
-
#
|
18
|
-
#
|
19
|
-
def persistence(service)
|
20
|
-
Thread.current.thread_variable_set(:persistence_service, service)
|
21
|
-
yield
|
22
|
-
ensure
|
23
|
-
Thread.current.thread_variable_set(:persistence_service, nil)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
module Rules
|
6
|
-
#
|
7
|
-
# Extends OpenHAB events
|
8
|
-
#
|
9
|
-
module Events
|
10
|
-
java_import org.openhab.core.events.AbstractEvent
|
11
|
-
|
12
|
-
# Add attachments to ItemEvent
|
13
|
-
class AbstractEvent
|
14
|
-
attr_accessor :attachment
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,160 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'method_source'
|
4
|
-
|
5
|
-
require 'openhab/core/thread_local'
|
6
|
-
require 'openhab/core/services'
|
7
|
-
require 'openhab/log/logger'
|
8
|
-
require_relative 'rule_config'
|
9
|
-
require_relative 'automation_rule'
|
10
|
-
require_relative 'guard'
|
11
|
-
require_relative 'name_inference'
|
12
|
-
|
13
|
-
module OpenHAB
|
14
|
-
#
|
15
|
-
# Contains code to create an OpenHAB DSL
|
16
|
-
#
|
17
|
-
module DSL
|
18
|
-
#
|
19
|
-
# Creates and manages OpenHAB Rules
|
20
|
-
#
|
21
|
-
module Rules
|
22
|
-
#
|
23
|
-
# The main rule DSL method
|
24
|
-
#
|
25
|
-
module Rule
|
26
|
-
include OpenHAB::Log
|
27
|
-
|
28
|
-
@script_rules = []
|
29
|
-
|
30
|
-
@automation_manager = OpenHAB::Core.automation_manager
|
31
|
-
@registry = OpenHAB::Core.rule_registry
|
32
|
-
class << self
|
33
|
-
attr_reader :script_rules, :automation_manager, :registry
|
34
|
-
end
|
35
|
-
|
36
|
-
module_function
|
37
|
-
|
38
|
-
#
|
39
|
-
# Create a new rule
|
40
|
-
#
|
41
|
-
# @param [String] rule_name The rule name
|
42
|
-
# @yield [] Block executed in context of a RuleConfig
|
43
|
-
#
|
44
|
-
#
|
45
|
-
def rule(rule_name = nil, id: nil, script: nil, &block) # rubocop:disable Metrics
|
46
|
-
id ||= NameInference.infer_rule_id_from_block(block)
|
47
|
-
script ||= block.source rescue nil # rubocop:disable Style/RescueModifier
|
48
|
-
|
49
|
-
OpenHAB::Core::ThreadLocal.thread_local(RULE_NAME: rule_name) do
|
50
|
-
@rule_name = rule_name
|
51
|
-
|
52
|
-
config = RuleConfig.new(block.binding)
|
53
|
-
config.uid(id)
|
54
|
-
config.instance_exec(config, &block)
|
55
|
-
config.guard = Guard::Guard.new(run_context: config.caller, only_if: config.only_if,
|
56
|
-
not_if: config.not_if)
|
57
|
-
|
58
|
-
rule_name ||= NameInference.infer_rule_name(config)
|
59
|
-
rule_name ||= id
|
60
|
-
|
61
|
-
config.name(rule_name)
|
62
|
-
logger.trace { config.inspect }
|
63
|
-
process_rule_config(config, script)
|
64
|
-
end
|
65
|
-
rescue StandardError => e
|
66
|
-
logger.log_exception(e, @rule_name)
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Cleanup rules in this script file
|
71
|
-
#
|
72
|
-
def self.cleanup_rules
|
73
|
-
@script_rules.each(&:cleanup)
|
74
|
-
end
|
75
|
-
Core::ScriptHandling.script_unloaded { cleanup_rules }
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
#
|
80
|
-
# Process a rule based on the supplied configuration
|
81
|
-
#
|
82
|
-
# @param [RuleConfig] config for rule
|
83
|
-
#
|
84
|
-
#
|
85
|
-
def process_rule_config(config, script) # rubocop:disable Metrics
|
86
|
-
return unless create_rule?(config)
|
87
|
-
|
88
|
-
rule = AutomationRule.new(config: config)
|
89
|
-
Rule.script_rules << rule
|
90
|
-
added_rule = add_rule(rule)
|
91
|
-
# add config so that MainUI can show the script
|
92
|
-
added_rule.actions.first.configuration.put('type', 'application/x-ruby')
|
93
|
-
added_rule.actions.first.configuration.put('script', script)
|
94
|
-
|
95
|
-
rule.execute(nil, { 'event' => Struct.new(:attachment).new(config.start_attachment) }) if config.on_start?
|
96
|
-
added_rule
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# Should a rule be created based on rule configuration
|
101
|
-
#
|
102
|
-
# @param [RuleConfig] config to check
|
103
|
-
#
|
104
|
-
# @return [Boolean] true if it should be created, false otherwise
|
105
|
-
#
|
106
|
-
def create_rule?(config)
|
107
|
-
if !triggers?(config)
|
108
|
-
logger.warn "Rule '#{config.name}' has no triggers, not creating rule"
|
109
|
-
elsif !execution_blocks?(config)
|
110
|
-
logger.warn "Rule '#{config.name}' has no execution blocks, not creating rule"
|
111
|
-
elsif !config.enabled
|
112
|
-
logger.trace "Rule '#{config.name}' marked as disabled, not creating rule."
|
113
|
-
else
|
114
|
-
return true
|
115
|
-
end
|
116
|
-
false
|
117
|
-
end
|
118
|
-
|
119
|
-
#
|
120
|
-
# Check if the rule has any triggers
|
121
|
-
#
|
122
|
-
# @param [RuleConfig] config to check for triggers
|
123
|
-
#
|
124
|
-
# @return [Boolean] True if rule has triggers, false otherwise
|
125
|
-
#
|
126
|
-
def triggers?(config)
|
127
|
-
config.on_start? || config.triggers.length.positive?
|
128
|
-
end
|
129
|
-
|
130
|
-
#
|
131
|
-
# Check if the rule has any execution blocks
|
132
|
-
#
|
133
|
-
# @param [RuleConfig] config to check for triggers
|
134
|
-
#
|
135
|
-
# @return [Boolean] True if rule has execution blocks, false otherwise
|
136
|
-
#
|
137
|
-
def execution_blocks?(config)
|
138
|
-
(config.run || []).length.positive?
|
139
|
-
end
|
140
|
-
|
141
|
-
#
|
142
|
-
# Add a rule to the automation managed
|
143
|
-
#
|
144
|
-
# @param [org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule] rule to add
|
145
|
-
#
|
146
|
-
#
|
147
|
-
def add_rule(rule)
|
148
|
-
base_uid = rule.uid
|
149
|
-
duplicate_index = 1
|
150
|
-
while $rules.get(rule.uid)
|
151
|
-
duplicate_index += 1
|
152
|
-
rule.uid = "#{base_uid} (#{duplicate_index})"
|
153
|
-
end
|
154
|
-
logger.trace("Adding rule: #{rule.inspect}")
|
155
|
-
Rule.automation_manager.addRule(rule)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|