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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "type"
|
|
4
|
+
|
|
5
|
+
module OpenHAB
|
|
6
|
+
module Core
|
|
7
|
+
module Types
|
|
8
|
+
UnDefType = org.openhab.core.types.UnDefType
|
|
9
|
+
|
|
10
|
+
# There are situations when item states do not have any defined value.
|
|
11
|
+
# This might be because they have not been initialized yet (never
|
|
12
|
+
# received an state update so far) or because their state is ambiguous
|
|
13
|
+
# (e.g. a group item with members whose states do not match will be
|
|
14
|
+
# {NULL}).
|
|
15
|
+
class UnDefType # rubocop:disable Lint/EmptyClass
|
|
16
|
+
# @!parse include State
|
|
17
|
+
|
|
18
|
+
# @!constant NULL
|
|
19
|
+
# Null State
|
|
20
|
+
# @!constant UNDEF
|
|
21
|
+
# Undef State
|
|
22
|
+
|
|
23
|
+
# @!method null?
|
|
24
|
+
# Check if `self` == {NULL}
|
|
25
|
+
# @return [true,false]
|
|
26
|
+
|
|
27
|
+
# @!method undef?
|
|
28
|
+
# Check if `self` == {UNDEF}
|
|
29
|
+
# @return [true,false]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @!parse
|
|
36
|
+
# UnDefType = OpenHAB::Core::Types::UnDefType
|
|
37
|
+
# NULL = OpenHAB::Core::Types::UnDefType::NULL
|
|
38
|
+
# UNDEF = OpenHAB::Core::Types::UnDefType::UNDEF
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "type"
|
|
4
|
+
|
|
5
|
+
module OpenHAB
|
|
6
|
+
module Core
|
|
7
|
+
module Types
|
|
8
|
+
UpDownType = org.openhab.core.library.types.UpDownType
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Implements the {UP} and {DOWN} commands.
|
|
12
|
+
#
|
|
13
|
+
# Also, {PercentType} can be converted to {UpDownType}
|
|
14
|
+
# for more semantic comparisons. `0` is {UP}, `100` is
|
|
15
|
+
# {DOWN}, and anything in-between is neither.
|
|
16
|
+
#
|
|
17
|
+
class UpDownType
|
|
18
|
+
# @!parse include Command, State
|
|
19
|
+
|
|
20
|
+
# @!constant UP
|
|
21
|
+
# Up Command/State
|
|
22
|
+
# @!constant DOWN
|
|
23
|
+
# Down Command/State
|
|
24
|
+
|
|
25
|
+
# @!method up?
|
|
26
|
+
# Check if `self == UP`
|
|
27
|
+
# @return [true,false]
|
|
28
|
+
|
|
29
|
+
# @!method down?
|
|
30
|
+
# Check if `self == DOWN`
|
|
31
|
+
# @return [true,false]
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# Invert the type
|
|
35
|
+
#
|
|
36
|
+
# @return [UpDownType] {UP} if {down?}, {DOWN} if {up?}
|
|
37
|
+
#
|
|
38
|
+
def !
|
|
39
|
+
return UP if down?
|
|
40
|
+
return DOWN if up?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @!parse
|
|
48
|
+
# UpDownType = OpenHAB::Core::Types::UpDownType
|
|
49
|
+
# UP = OpenHAB::Core::Types::UpDownType::UP
|
|
50
|
+
# DOWN = OpenHAB::Core::Types::UpDownType::DOWN
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Dir[File.expand_path("types/*.rb", __dir__)].sort.each do |f|
|
|
4
|
+
require f
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module OpenHAB
|
|
8
|
+
module Core
|
|
9
|
+
#
|
|
10
|
+
# Contains the core types that openHAB uses as {State}s for items, and
|
|
11
|
+
# {Command}s to be sent to control them.
|
|
12
|
+
#
|
|
13
|
+
# Types are the specific data types that commands and states are. They can be
|
|
14
|
+
# sent to items, be the current state of an item, or be the `command`, `state`,
|
|
15
|
+
# and `was` field of various
|
|
16
|
+
# {group::OpenHAB::DSL::Rules::BuilderDSL::Triggers triggers}.
|
|
17
|
+
# Some types have additional useful methods.
|
|
18
|
+
#
|
|
19
|
+
module Types
|
|
20
|
+
# Hash taking a Enum value, and returning two symbols of
|
|
21
|
+
# predicates to be defined for it. the first is the "command" form,
|
|
22
|
+
# which should be defined on ItemCommandEvent, and on the Type itself.
|
|
23
|
+
# the second is "state" form, which should be defined on the applicable
|
|
24
|
+
# Item, and on the Type itself.
|
|
25
|
+
# @!visibility private
|
|
26
|
+
PREDICATE_ALIASES = Hash.new { |_h, k| [:"#{k.downcase}?"] * 2 }
|
|
27
|
+
.merge({
|
|
28
|
+
"PLAY" => %i[play? playing?],
|
|
29
|
+
"PAUSE" => %i[pause? paused?],
|
|
30
|
+
"REWIND" => %i[rewind? rewinding?],
|
|
31
|
+
"FASTFORWARD" => %i[fast_forward? fast_forwarding?]
|
|
32
|
+
}).freeze
|
|
33
|
+
|
|
34
|
+
# Hash taking a Enum value, and returning an array of symbols
|
|
35
|
+
# of the command to define for it
|
|
36
|
+
# @!visibility private
|
|
37
|
+
COMMAND_ALIASES = Hash.new { |_h, k| k.downcase.to_sym }
|
|
38
|
+
.merge({
|
|
39
|
+
"FASTFORWARD" => :fast_forward
|
|
40
|
+
}).freeze
|
|
41
|
+
|
|
42
|
+
constants.map { |c| const_get(c) }
|
|
43
|
+
.grep(Module)
|
|
44
|
+
.select { |k| k < java.lang.Enum }
|
|
45
|
+
.each do |klass|
|
|
46
|
+
# make sure == from Type is inherited
|
|
47
|
+
klass.remove_method(:==)
|
|
48
|
+
|
|
49
|
+
# dynamically define predicate methods
|
|
50
|
+
klass.values.each do |value| # rubocop:disable Style/HashEachMethods this isn't a Ruby hash
|
|
51
|
+
# include all the aliases that we define for items both command and
|
|
52
|
+
# state aliases (since types can be interrogated as an incoming
|
|
53
|
+
# command, or as the state of an item)
|
|
54
|
+
command = :"#{Types::COMMAND_ALIASES[value.to_s]}?"
|
|
55
|
+
states = Types::PREDICATE_ALIASES[value.to_s]
|
|
56
|
+
|
|
57
|
+
([command] | states).each do |method|
|
|
58
|
+
logger.trace("Defining #{klass}##{method} for #{value}")
|
|
59
|
+
klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
60
|
+
def #{method} # def on?
|
|
61
|
+
as(#{value.class.java_class.simple_name}).equal?(#{value}) # as(OnOffType).equal?(ON)
|
|
62
|
+
end # end
|
|
63
|
+
RUBY
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
method = states.last
|
|
67
|
+
Events::ItemState.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
68
|
+
def #{method} # def on?
|
|
69
|
+
item_state.as(#{value.class.java_class.simple_name}).equal?(#{value}) # item_state.as(OnOffType).equal?(ON)
|
|
70
|
+
end # end
|
|
71
|
+
RUBY
|
|
72
|
+
|
|
73
|
+
Events::ItemStateChangedEvent.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
74
|
+
def was_#{method} # def was_on?
|
|
75
|
+
old_item_state.as(#{value.class.java_class.simple_name}).equal?(#{value}) # old_item_state.as(OnOffType).equal?(ON)
|
|
76
|
+
end # end
|
|
77
|
+
RUBY
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module OpenHAB
|
|
4
|
-
module
|
|
4
|
+
module Core
|
|
5
5
|
java_import org.openhab.core.common.AbstractUID
|
|
6
|
-
java_import org.openhab.core.thing.ThingTypeUID
|
|
7
6
|
|
|
8
|
-
# Adds methods to core
|
|
7
|
+
# Adds methods to core openHAB AbstractUID to make it more natural in Ruby
|
|
9
8
|
class AbstractUID
|
|
10
9
|
# implicit conversion to string
|
|
11
|
-
|
|
10
|
+
alias_method :to_str, :to_s
|
|
12
11
|
# inspect result is just the string representation
|
|
13
|
-
|
|
12
|
+
alias_method :inspect, :to_s
|
|
14
13
|
|
|
15
14
|
# compares if equal to `other`, including string conversion
|
|
16
15
|
# @return [true, false]
|
|
@@ -21,24 +20,6 @@ module OpenHAB
|
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
# Adds methods to core OpenHAB ThingUID to make it more natural in Ruby
|
|
25
|
-
class ThingUID
|
|
26
|
-
# Returns the id of the binding this thing belongs to
|
|
27
|
-
# @return [String]
|
|
28
|
-
def binding_id
|
|
29
|
-
get_segment(0)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Adds methods to core OpenHAB ThingTypeUID to make it more natural in Ruby
|
|
34
|
-
class ThingTypeUID
|
|
35
|
-
# Returns the id of the binding this thing type belongs to
|
|
36
|
-
# @return [String]
|
|
37
|
-
def binding_id
|
|
38
|
-
get_segment(0)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
23
|
# have to remove == from all descendant classes so that they'll inherit
|
|
43
24
|
# the new implementation
|
|
44
25
|
[org.openhab.core.items.MetadataKey,
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
OpenHAB::Core.import_preset("cache")
|
|
4
|
+
unless defined?($sharedCache)
|
|
5
|
+
$sharedCache = nil
|
|
6
|
+
return
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module OpenHAB
|
|
10
|
+
module Core
|
|
11
|
+
# @interface
|
|
12
|
+
java_import org.openhab.core.automation.module.script.rulesupport.shared.ValueCache
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# ValueCache is the interface used to access a
|
|
16
|
+
# {OpenHAB::DSL.shared_cache shared cache} available between scripts and/or
|
|
17
|
+
# rule executions.
|
|
18
|
+
#
|
|
19
|
+
# While ValueCache looks somewhat like a Hash, it does not support
|
|
20
|
+
# iteration of the contained elements. So it's limited to strictly storing,
|
|
21
|
+
# fetching, or removing known elements.
|
|
22
|
+
#
|
|
23
|
+
# Shared caches are _not_ persisted between openHAB restarts. And in fact,
|
|
24
|
+
# if all scripts are unloaded that reference a particular key, that key is
|
|
25
|
+
# removed.
|
|
26
|
+
#
|
|
27
|
+
# @note Only the {OpenHAB::DSL.shared_cache sharedCache} is exposed in Ruby.
|
|
28
|
+
# For a private cache, simply use an instance variable. See
|
|
29
|
+
# {file:docs/ruby-basics.md#variables Instance Variables}.
|
|
30
|
+
#
|
|
31
|
+
# @note Because every script or UI rule gets it own JRuby engine instance,
|
|
32
|
+
# you cannot rely on being able to access Ruby objects between them. Only
|
|
33
|
+
# objects that implement a Java interface that's part of Java or openHAB
|
|
34
|
+
# Core (such as Hash implements {java.util.Map}, or other basic
|
|
35
|
+
# datatypes) can be reliably stored and accessed from the shared cache.
|
|
36
|
+
# Likewise, you can use the cache to access data from other scripting
|
|
37
|
+
# languages, but they'll be all but useless in Ruby. It's best to stick
|
|
38
|
+
# to simple data types. If you're having troubles, serializing to_json
|
|
39
|
+
# before storing may help.
|
|
40
|
+
#
|
|
41
|
+
# @see https://www.openhab.org/docs/configuration/jsr223.html#cache-preset openHAB Cache Preset
|
|
42
|
+
#
|
|
43
|
+
# @example
|
|
44
|
+
# shared_cache.compute_if_absent(:execution_count) { 0 }
|
|
45
|
+
# shared_cache[:execution_count] += 1
|
|
46
|
+
#
|
|
47
|
+
module ValueCache
|
|
48
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-5B-5D Hash#[]
|
|
49
|
+
def [](key)
|
|
50
|
+
get(key.to_s)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Compute and store new value for key if the key is absent. This method is atomic.
|
|
55
|
+
#
|
|
56
|
+
# @param [String] key
|
|
57
|
+
# @yieldreturn [Object] new value
|
|
58
|
+
# @return [Object] new value or current value
|
|
59
|
+
#
|
|
60
|
+
def compute_if_absent(key, &block)
|
|
61
|
+
get(key.to_s, &block)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-5B-5D-3D Hash#[]=
|
|
65
|
+
def []=(key, value)
|
|
66
|
+
put(key.to_s, value)
|
|
67
|
+
end
|
|
68
|
+
alias_method :store, :[]
|
|
69
|
+
|
|
70
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-delete Hash#delete
|
|
71
|
+
def delete(key)
|
|
72
|
+
key = key.to_s
|
|
73
|
+
if block_given?
|
|
74
|
+
fetch(key) do
|
|
75
|
+
return yield(key)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
remove(key)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-fetch Hash#fetch
|
|
82
|
+
#
|
|
83
|
+
# @example
|
|
84
|
+
# shared_cache.fetch(:key_from_another_script) # raises NoKeyError
|
|
85
|
+
#
|
|
86
|
+
def fetch(key, *default_value)
|
|
87
|
+
if default_value.length > 1
|
|
88
|
+
raise ArgumentError,
|
|
89
|
+
"wrong number of arguments (given #{default_value.length + 1}, expected 0..1)"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
key = key.to_s
|
|
93
|
+
if default_value.empty?
|
|
94
|
+
if block_given?
|
|
95
|
+
get(key) do
|
|
96
|
+
return yield(key)
|
|
97
|
+
end
|
|
98
|
+
else
|
|
99
|
+
get(key) do
|
|
100
|
+
raise KeyError.new("key not found: #{key.inspect}", key: key)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
else
|
|
104
|
+
get(key) { return default_value.first }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-assoc Hash#assoc
|
|
109
|
+
def assoc(key)
|
|
110
|
+
[key, fetch(key) do
|
|
111
|
+
# return nil directly, without storing a value to the cache
|
|
112
|
+
return nil
|
|
113
|
+
end]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-dig Hash#dig
|
|
117
|
+
def dig(key, *identifiers)
|
|
118
|
+
r = fetch(key) { return nil }
|
|
119
|
+
r&.dig(*identifiers)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-fetch_values Hash#fetch_values
|
|
123
|
+
def fetch_values(*keys, &block)
|
|
124
|
+
result = []
|
|
125
|
+
keys.each do |key|
|
|
126
|
+
if block
|
|
127
|
+
result << fetch(key, &block)
|
|
128
|
+
else
|
|
129
|
+
has_value = true
|
|
130
|
+
value = fetch(key) { has_value = false }
|
|
131
|
+
result << value if has_value
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
result
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-key-3F Hash#key?
|
|
138
|
+
def key?(key)
|
|
139
|
+
!!fetch(key) { return false }
|
|
140
|
+
end
|
|
141
|
+
alias_method :has_key?, :key?
|
|
142
|
+
alias_method :include?, :key?
|
|
143
|
+
alias_method :member?, :key?
|
|
144
|
+
|
|
145
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-merge-21 Hash#merge!
|
|
146
|
+
def merge!(*other_hashes)
|
|
147
|
+
other_hashes.each do |hash|
|
|
148
|
+
hash.each do |(k, v)|
|
|
149
|
+
k = k.to_s
|
|
150
|
+
if block_given?
|
|
151
|
+
dup = true
|
|
152
|
+
old_value = fetch(k) do
|
|
153
|
+
dup = false
|
|
154
|
+
end
|
|
155
|
+
self[k] = dup ? yield(k, old_value, v) : v
|
|
156
|
+
else
|
|
157
|
+
self[k] = v
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
self
|
|
162
|
+
end
|
|
163
|
+
alias_method :update, :merge!
|
|
164
|
+
|
|
165
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-slice Hash#slice
|
|
166
|
+
def slice(*keys)
|
|
167
|
+
result = {}
|
|
168
|
+
keys.each do |k|
|
|
169
|
+
k = k.to_s
|
|
170
|
+
result[k] = self[k] if key?(k)
|
|
171
|
+
end
|
|
172
|
+
result
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-to_proc Hash#to_proc
|
|
176
|
+
def to_proc
|
|
177
|
+
@to_proc ||= ->(k) { self[k] }
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-values_at Hash#values_at
|
|
181
|
+
def values_at(*keys)
|
|
182
|
+
keys.map do |k|
|
|
183
|
+
self[k]
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
data/lib/openhab/core.rb
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenHAB
|
|
4
|
+
# Contains classes and modules that wrap actual openHAB objects
|
|
5
|
+
module Core
|
|
6
|
+
# The openHAB Version. >= 3.4.0 is required.
|
|
7
|
+
# @return [String]
|
|
8
|
+
VERSION = org.openhab.core.OpenHAB.version.freeze
|
|
9
|
+
|
|
10
|
+
raise "`openhab-scripting` requires openHAB >= 3.4.0" unless Gem::Version.new(VERSION) >= Gem::Version.new("3.4.0")
|
|
11
|
+
|
|
12
|
+
# @return [Integer] Number of seconds to wait between checks for automation manager
|
|
13
|
+
CHECK_DELAY = 10
|
|
14
|
+
private_constant :CHECK_DELAY
|
|
15
|
+
class << self
|
|
16
|
+
#
|
|
17
|
+
# Wait until openHAB engine ready to process
|
|
18
|
+
#
|
|
19
|
+
# @return [void]
|
|
20
|
+
#
|
|
21
|
+
# @!visibility private
|
|
22
|
+
def wait_till_openhab_ready
|
|
23
|
+
logger.trace("Checking readiness of openHAB")
|
|
24
|
+
until automation_manager
|
|
25
|
+
logger.trace("Automation manager not loaded, checking again in #{CHECK_DELAY} seconds.")
|
|
26
|
+
sleep CHECK_DELAY
|
|
27
|
+
end
|
|
28
|
+
logger.trace "Automation manager instantiated, openHAB ready for rule processing."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# @!attribute [r] config_folder
|
|
33
|
+
# @return [Pathname] The configuration folder path.
|
|
34
|
+
#
|
|
35
|
+
def config_folder
|
|
36
|
+
Pathname.new(org.openhab.core.OpenHAB.config_folder)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# @!attribute [r] automation_manager
|
|
41
|
+
# @return [org.openhab.core.automation.module.script.rulesupport.shared.ScriptedAutomationManager]
|
|
42
|
+
# The openHAB Automation manager.
|
|
43
|
+
#
|
|
44
|
+
def automation_manager
|
|
45
|
+
$se.get("automationManager")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
# Imports a specific script extension preset into the global namespace
|
|
50
|
+
#
|
|
51
|
+
# @param [String] preset
|
|
52
|
+
# @return [void]
|
|
53
|
+
#
|
|
54
|
+
def import_preset(preset)
|
|
55
|
+
import_scope_values($se.import_preset(preset))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# Imports all default script extension presets into the global namespace
|
|
60
|
+
#
|
|
61
|
+
# @!visibility private
|
|
62
|
+
# @return [void]
|
|
63
|
+
#
|
|
64
|
+
def import_default_presets
|
|
65
|
+
$se.default_presets.each { |preset| import_preset(preset) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# Imports concrete scope values into the global namespace
|
|
70
|
+
#
|
|
71
|
+
# @param [java.util.Map<String, Object>] scope_values
|
|
72
|
+
# @!visibility private
|
|
73
|
+
# @return [void]
|
|
74
|
+
#
|
|
75
|
+
def import_scope_values(scope_values)
|
|
76
|
+
scope_values.for_each do |key, value|
|
|
77
|
+
# convert Java classes to Ruby classes
|
|
78
|
+
value = value.ruby_class if value.is_a?(java.lang.Class) # rubocop:disable Lint/UselessAssignment
|
|
79
|
+
# variables are globals; constants go into the global namespace
|
|
80
|
+
key = case key[0]
|
|
81
|
+
when "a".."z" then "$#{key}"
|
|
82
|
+
when "A".."Z" then "::#{key}"
|
|
83
|
+
end
|
|
84
|
+
eval("#{key} = value unless defined?(#{key})", nil, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
import_default_presets unless defined?($ir)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# several classes rely on this, so force it to load earlier
|
|
94
|
+
require_relative "core/provider"
|
|
95
|
+
|
|
96
|
+
Dir[File.expand_path("core/**/*.rb", __dir__)].sort.each do |f|
|
|
97
|
+
require f
|
|
98
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenHAB
|
|
4
|
+
module CoreExt
|
|
5
|
+
# Extensions that apply to both Date and Time classes
|
|
6
|
+
module Between
|
|
7
|
+
#
|
|
8
|
+
# Checks whether the the object falls between the given range.
|
|
9
|
+
#
|
|
10
|
+
# @overload between?(min, max)
|
|
11
|
+
# @param [Object] min The minimum value to check, inclusive
|
|
12
|
+
# @param [Object] max The maximum value to check, inclusive
|
|
13
|
+
# @return [true,false]
|
|
14
|
+
#
|
|
15
|
+
# @overload between?(range)
|
|
16
|
+
# @param [Range] range A range to check
|
|
17
|
+
# @return [true,false]
|
|
18
|
+
#
|
|
19
|
+
def between?(min, max = nil)
|
|
20
|
+
range = if max
|
|
21
|
+
Range.new(min, max, false)
|
|
22
|
+
else
|
|
23
|
+
raise ArgumentError, "Expecting a range when given a single argument" unless min.is_a?(Range)
|
|
24
|
+
|
|
25
|
+
min
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
OpenHAB::DSL.between(range).cover?(self)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenHAB
|
|
4
|
+
module CoreExt
|
|
5
|
+
#
|
|
6
|
+
# Forwards ephemeris helper methods to `#to_zoned_date_time` provided by
|
|
7
|
+
# the mixed-in class.
|
|
8
|
+
#
|
|
9
|
+
# @note openHAB's built-in holiday definitions are based on _bank_
|
|
10
|
+
# holidays, so may give some unexpected results. For example, 2022-12-25
|
|
11
|
+
# is _not_ Christmas in England because it lands on a Sunday that year,
|
|
12
|
+
# so Christmas is considered to be 2022-12-26. See
|
|
13
|
+
# [the source](https://github.com/svendiedrichsen/jollyday/tree/master/src/main/resources/holidays)
|
|
14
|
+
# for exact definitions. You can always provide your own holiday
|
|
15
|
+
# definitions with {OpenHAB::DSL.holiday_file holiday_file} or
|
|
16
|
+
# {OpenHAB::DSL.holiday_file! holiday_file!}.
|
|
17
|
+
#
|
|
18
|
+
# @see https://www.openhab.org/docs/configuration/actions.html#ephemeris Ephemeris Action
|
|
19
|
+
# @see Core::Actions::Ephemeris.holiday_name Ephemeris.holiday_name
|
|
20
|
+
#
|
|
21
|
+
module Ephemeris
|
|
22
|
+
# (see Java::ZonedDateTime#holiday)
|
|
23
|
+
def holiday(holiday_file = nil)
|
|
24
|
+
to_zoned_date_time.holiday(holiday_file)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# (see Java::ZonedDateTime#holiday?)
|
|
28
|
+
def holiday?(holiday_file = nil)
|
|
29
|
+
to_zoned_date_time.holiday?(holiday_file)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# (see Java::ZonedDateTime#next_holiday)
|
|
33
|
+
def next_holiday(holiday_file = nil)
|
|
34
|
+
to_zoned_date_time.next_holiday(holiday_file)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# (see Java::ZonedDateTime#weekend?)
|
|
38
|
+
def weekend?
|
|
39
|
+
to_zoned_date_time.weekend?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# (see Java::ZonedDateTime#in_dayset?)
|
|
43
|
+
def in_dayset?(set)
|
|
44
|
+
to_zoned_date_time.in_dayset?(set)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# (see Java::ZonedDateTime#days_until)
|
|
48
|
+
def days_until(holiday, holiday_file = nil)
|
|
49
|
+
to_zoned_date_time.days_until(holiday, holiday_file)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenHAB
|
|
4
|
+
module CoreExt
|
|
5
|
+
module Java
|
|
6
|
+
Class = java.lang.Class
|
|
7
|
+
|
|
8
|
+
# Extensions to Class
|
|
9
|
+
class Class
|
|
10
|
+
#
|
|
11
|
+
# `self`, all superclasses and interfaces, recursively.
|
|
12
|
+
#
|
|
13
|
+
# @return [Array<Class>]
|
|
14
|
+
#
|
|
15
|
+
def ancestors
|
|
16
|
+
([self] +
|
|
17
|
+
Array(superclass&.ancestors) +
|
|
18
|
+
interfaces.flat_map(&:ancestors)).uniq
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# `self`, all superclasses and interfaces, recursively.
|
|
23
|
+
#
|
|
24
|
+
# @return [Array<java.lang.reflect.Type>]
|
|
25
|
+
#
|
|
26
|
+
def generic_ancestors
|
|
27
|
+
ancestors.flat_map do |klass|
|
|
28
|
+
Array(klass.generic_superclass) + klass.generic_interfaces
|
|
29
|
+
end.uniq
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|