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,433 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
|
|
5
|
+
module OpenHAB
|
|
6
|
+
module Core
|
|
7
|
+
module Items
|
|
8
|
+
module Metadata
|
|
9
|
+
#
|
|
10
|
+
# {Hash} represents the configuration for a single metadata namespace.
|
|
11
|
+
#
|
|
12
|
+
# It implements the entire interface of {::Hash}.
|
|
13
|
+
#
|
|
14
|
+
# All keys are converted to strings.
|
|
15
|
+
#
|
|
16
|
+
# @!attribute [rw] value
|
|
17
|
+
# @return [String] The main value for the metadata namespace.
|
|
18
|
+
# @!attribute [r] namespace
|
|
19
|
+
# @return [String]
|
|
20
|
+
#
|
|
21
|
+
class Hash
|
|
22
|
+
java_import org.openhab.core.items.Metadata
|
|
23
|
+
private_constant :Metadata
|
|
24
|
+
|
|
25
|
+
include Enumerable
|
|
26
|
+
|
|
27
|
+
extend Forwardable
|
|
28
|
+
def_delegators :@metadata, :configuration, :hash, :to_s, :uid, :value
|
|
29
|
+
private :configuration
|
|
30
|
+
|
|
31
|
+
# @!method to_hash
|
|
32
|
+
# Implicit conversion to {::Hash}.
|
|
33
|
+
# @return [::Hash]
|
|
34
|
+
|
|
35
|
+
# Make it act like a Hash; some methods can be handled by
|
|
36
|
+
# java.util.Map, others we have to convert to a Ruby Hash first, and
|
|
37
|
+
# still others (mutators) must be manually implemented below.
|
|
38
|
+
def_delegators :configuration,
|
|
39
|
+
:any?,
|
|
40
|
+
:compact,
|
|
41
|
+
:compare_by_identity?,
|
|
42
|
+
:deconstruct_keys,
|
|
43
|
+
:default,
|
|
44
|
+
:default_proc,
|
|
45
|
+
:each,
|
|
46
|
+
:each_key,
|
|
47
|
+
:each_pair,
|
|
48
|
+
:each_value,
|
|
49
|
+
:empty?,
|
|
50
|
+
:filter,
|
|
51
|
+
:flatten,
|
|
52
|
+
:has_value?,
|
|
53
|
+
:invert,
|
|
54
|
+
:key,
|
|
55
|
+
:keys,
|
|
56
|
+
:length,
|
|
57
|
+
:rassoc,
|
|
58
|
+
:reject,
|
|
59
|
+
:select,
|
|
60
|
+
:shift,
|
|
61
|
+
:size,
|
|
62
|
+
:to_a,
|
|
63
|
+
:to_h,
|
|
64
|
+
:to_hash,
|
|
65
|
+
:transform_keys,
|
|
66
|
+
:transform_values,
|
|
67
|
+
:values,
|
|
68
|
+
:value?
|
|
69
|
+
|
|
70
|
+
def_delegator :uid, :namespace
|
|
71
|
+
|
|
72
|
+
class << self
|
|
73
|
+
# @!visibility private
|
|
74
|
+
def from_item(item_name, namespace, value)
|
|
75
|
+
namespace = namespace.to_s
|
|
76
|
+
value = case value
|
|
77
|
+
when Hash
|
|
78
|
+
return value if value.uid.item_name == item_name && value.uid.namespace == namespace
|
|
79
|
+
|
|
80
|
+
[value.value, value.send(:configuration)]
|
|
81
|
+
when Array
|
|
82
|
+
raise ArgumentError, "Array must contain 2 elements: value, config" if value.length != 2
|
|
83
|
+
|
|
84
|
+
[value.first, (value.last || {}).transform_keys(&:to_s)]
|
|
85
|
+
when ::Hash then ["", value.transform_keys(&:to_s)]
|
|
86
|
+
else [value.to_s, {}]
|
|
87
|
+
end
|
|
88
|
+
new(Metadata.new(org.openhab.core.items.MetadataKey.new(namespace.to_s, item_name), *value))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @!visibility private
|
|
92
|
+
def from_value(namespace, value)
|
|
93
|
+
from_item("-", namespace, value)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# @!visibility private
|
|
98
|
+
def initialize(metadata = nil)
|
|
99
|
+
@metadata = metadata
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# @!visibility private
|
|
103
|
+
def dup
|
|
104
|
+
new(Metadata.new(org.openhab.core.items.MetadataKey.new(uid.namespace, "-"), value, configuration))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Is this object attached to an actual Item?
|
|
108
|
+
# @return [true,false]
|
|
109
|
+
def attached?
|
|
110
|
+
uid.item_name != "-"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @!attribute [r] item
|
|
114
|
+
# @return [Item, nil] The item this namespace is attached to.
|
|
115
|
+
def item
|
|
116
|
+
return nil unless attached?
|
|
117
|
+
|
|
118
|
+
DSL.items[uid.item_name]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# @!visibility private
|
|
122
|
+
def commit
|
|
123
|
+
return unless attached?
|
|
124
|
+
|
|
125
|
+
javaify
|
|
126
|
+
provider.update(@metadata)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# @!visibility private
|
|
130
|
+
def create_or_update
|
|
131
|
+
return unless attached?
|
|
132
|
+
|
|
133
|
+
javaify
|
|
134
|
+
(p = provider).get(uid) ? p.update(@metadata) : p.add(@metadata)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# @!visibility private
|
|
138
|
+
def remove
|
|
139
|
+
provider.remove(uid)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# @!visibility private
|
|
143
|
+
def eql?(other)
|
|
144
|
+
return true if equal?(other)
|
|
145
|
+
return false unless other.is_a?(Hash)
|
|
146
|
+
return false unless value == other.value
|
|
147
|
+
|
|
148
|
+
configuration == other.configuration
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
#
|
|
152
|
+
# Set the metadata value
|
|
153
|
+
#
|
|
154
|
+
def value=(value)
|
|
155
|
+
@metadata = org.openhab.core.items.Metadata.new(uid, value.to_s, configuration)
|
|
156
|
+
commit
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# @!visibility private
|
|
160
|
+
def <(other)
|
|
161
|
+
if other.is_a?(Hash)
|
|
162
|
+
return false if attached? && uid == other.uid
|
|
163
|
+
return false unless value == other.value
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
configuration < other
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @!visibility private
|
|
170
|
+
def <=(other)
|
|
171
|
+
if other.is_a?(Hash)
|
|
172
|
+
return true if attached? && uid == other.uid
|
|
173
|
+
return false unless value == other.value
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
configuration <= other
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# @!visibility private
|
|
180
|
+
def ==(other)
|
|
181
|
+
if other.is_a?(Hash)
|
|
182
|
+
return false unless value == other.value
|
|
183
|
+
|
|
184
|
+
return configuration == other.configuration
|
|
185
|
+
elsif value.empty? && other.respond_to?(:to_hash)
|
|
186
|
+
return configuration == other.to_hash
|
|
187
|
+
end
|
|
188
|
+
false
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# @!visibility private
|
|
192
|
+
def >(other)
|
|
193
|
+
if other.is_a?(Hash)
|
|
194
|
+
return false if attached? && uid == other.uid
|
|
195
|
+
return false unless value == other.value
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
configuration > other
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# @!visibility private
|
|
202
|
+
def >=(other)
|
|
203
|
+
if other.is_a?(Hash)
|
|
204
|
+
return true if attached? && uid == other.uid
|
|
205
|
+
return false unless value == other.value
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
configuration >= other
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# @!visibility private
|
|
212
|
+
def [](key)
|
|
213
|
+
configuration[key.to_s]
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# @!visibility private
|
|
217
|
+
def []=(key, value)
|
|
218
|
+
key = key.to_s
|
|
219
|
+
new_config = to_h
|
|
220
|
+
new_config[key] = value
|
|
221
|
+
replace(new_config)
|
|
222
|
+
value # rubocop:disable Lint/Void
|
|
223
|
+
end
|
|
224
|
+
alias_method :store, :[]=
|
|
225
|
+
|
|
226
|
+
# @!visibility private
|
|
227
|
+
def assoc(key)
|
|
228
|
+
configuration.assoc(key.to_s)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# @!visibility private
|
|
232
|
+
def clear
|
|
233
|
+
replace({})
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# @!visibility private
|
|
237
|
+
def compact!
|
|
238
|
+
replace(compact)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# @!visibility private
|
|
242
|
+
def compare_by_identity
|
|
243
|
+
raise NotImplementedError
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# @!visibility private
|
|
247
|
+
def default=(*)
|
|
248
|
+
raise NotImplementedError
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# @!visibility private
|
|
252
|
+
def default_proc=(*)
|
|
253
|
+
raise NotImplementedError
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# @!visibility private
|
|
257
|
+
def delete(key)
|
|
258
|
+
key = key.to_s
|
|
259
|
+
new_config = to_h
|
|
260
|
+
return yield(key) if block_given? && !new_config.key?(key)
|
|
261
|
+
|
|
262
|
+
old_value = new_config.delete(key)
|
|
263
|
+
replace(new_config)
|
|
264
|
+
old_value
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# @!visibility private
|
|
268
|
+
def delete_if(&block)
|
|
269
|
+
raise NotImplementedError unless block
|
|
270
|
+
|
|
271
|
+
replace(to_h.delete_if(block))
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# @!visibility private
|
|
275
|
+
def dig(key, *keys)
|
|
276
|
+
configuration.dig(key.to_s, *keys)
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# @!visibility private
|
|
280
|
+
def except(*keys)
|
|
281
|
+
to_h.except(*keys.map(&:to_s))
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# @!visibility private
|
|
285
|
+
def fetch(key, &block)
|
|
286
|
+
configuration.fetch(key.to_s, &block)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# @!visibility private
|
|
290
|
+
def fetch_values(*keys, &block)
|
|
291
|
+
configuration.fetch_values(*keys.map(&:to_s), &block)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# @!visibility private
|
|
295
|
+
def keep_if(&block)
|
|
296
|
+
select!(&block)
|
|
297
|
+
self
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# @!visibility private
|
|
301
|
+
def key?(key)
|
|
302
|
+
configuration.key?(key.to_s)
|
|
303
|
+
end
|
|
304
|
+
alias_method :include?, :key?
|
|
305
|
+
alias_method :has_key?, :key?
|
|
306
|
+
alias_method :member?, :key?
|
|
307
|
+
|
|
308
|
+
# @!visibility private
|
|
309
|
+
def merge!(*others, &block)
|
|
310
|
+
return self if others.empty?
|
|
311
|
+
|
|
312
|
+
new_config = to_h
|
|
313
|
+
others.each do |h|
|
|
314
|
+
new_config.merge!(h.transform_keys(&:to_s), &block)
|
|
315
|
+
end
|
|
316
|
+
replace(new_config)
|
|
317
|
+
end
|
|
318
|
+
alias_method :update, :merge!
|
|
319
|
+
|
|
320
|
+
# @!visibility private
|
|
321
|
+
def reject!(&block)
|
|
322
|
+
raise NotImplementedError unless block
|
|
323
|
+
|
|
324
|
+
r = to_h.reject!(&block)
|
|
325
|
+
replace(r) if r
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
#
|
|
329
|
+
# Replace the configuration with a new {::Hash}.
|
|
330
|
+
#
|
|
331
|
+
# @param [::Hash] new_config
|
|
332
|
+
# @return [self]
|
|
333
|
+
#
|
|
334
|
+
def replace(new_config)
|
|
335
|
+
@metadata = org.openhab.core.items.Metadata.new(uid, value, new_config.transform_keys(&:to_s))
|
|
336
|
+
commit
|
|
337
|
+
self
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# @!visibility private
|
|
341
|
+
def select!(&block)
|
|
342
|
+
raise NotImplementedError unless block?
|
|
343
|
+
|
|
344
|
+
r = to_h.select!(&block)
|
|
345
|
+
replace(r) if r
|
|
346
|
+
end
|
|
347
|
+
alias_method :filter!, :select!
|
|
348
|
+
|
|
349
|
+
# @!visibility private
|
|
350
|
+
def slice(*keys)
|
|
351
|
+
configuration.slice(*keys.map(&:to_s))
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# @!visibility private
|
|
355
|
+
def to_proc
|
|
356
|
+
->(k) { self[k] }
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# @!visibility private
|
|
360
|
+
def transform_keys!(*args, &block)
|
|
361
|
+
replace(transform_keys(*args, &block))
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# @!visibility private
|
|
365
|
+
def transform_values!(&block)
|
|
366
|
+
raise NotImplementedError unless block
|
|
367
|
+
|
|
368
|
+
replace(transform_values(&block))
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# @!visibility private
|
|
372
|
+
def values_at(*keys)
|
|
373
|
+
configuration.values_at(*keys.map(&:to_s))
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# @!visibility private
|
|
377
|
+
def inspect
|
|
378
|
+
return to_h.inspect if value.empty?
|
|
379
|
+
return value.inspect if configuration.empty?
|
|
380
|
+
|
|
381
|
+
[value, to_h].inspect
|
|
382
|
+
end
|
|
383
|
+
remove_method :to_s
|
|
384
|
+
alias_method :to_s, :inspect
|
|
385
|
+
|
|
386
|
+
#
|
|
387
|
+
# @raise [FrozenError] if the provider is not a
|
|
388
|
+
# {org.openhab.core.common.registry.ManagedProvider ManagedProvider} that can be updated.
|
|
389
|
+
# @return [org.openhab.core.common.registry.ManagedProvider]
|
|
390
|
+
#
|
|
391
|
+
def provider
|
|
392
|
+
preferred_provider = Provider.current(
|
|
393
|
+
Thread.current[:openhab_providers]&.dig(:metadata_items, uid.item_name) ||
|
|
394
|
+
Thread.current[:openhab_providers]&.dig(:metadata_namespaces, uid.namespace),
|
|
395
|
+
self
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
if attached?
|
|
399
|
+
provider = Provider.registry.provider_for(uid)
|
|
400
|
+
return preferred_provider unless provider
|
|
401
|
+
|
|
402
|
+
unless provider.is_a?(org.openhab.core.common.registry.ManagedProvider)
|
|
403
|
+
raise FrozenError, "Cannot modify metadata from provider #{provider.inspect} for #{uid}."
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
if preferred_provider != provider
|
|
407
|
+
logger.warn("Provider #{preferred_provider.inspect} cannot be used with #{uid}; " \
|
|
408
|
+
"reverting to provider #{provider.inspect}. " \
|
|
409
|
+
"This may cause unexpected issues, like metadata persisting that you did not expect to.")
|
|
410
|
+
preferred_provider = provider
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
end
|
|
414
|
+
preferred_provider
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
private
|
|
418
|
+
|
|
419
|
+
#
|
|
420
|
+
# @see https://github.com/openhab/openhab-core/issues/3169
|
|
421
|
+
#
|
|
422
|
+
# in the meantime, force the serialization round-trip right now
|
|
423
|
+
#
|
|
424
|
+
def javaify
|
|
425
|
+
mapper = Provider.registry.managed_provider.get.storage.entityMapper
|
|
426
|
+
|
|
427
|
+
@metadata = mapper.from_json(mapper.to_json_tree(@metadata), Metadata.java_class)
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
end
|