openhab-scripting 4.46.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/openhab/core/actions/audio.rb +47 -0
- data/lib/openhab/core/actions/ephemeris.rb +39 -0
- data/lib/openhab/core/actions/exec.rb +51 -0
- data/lib/openhab/core/actions/http.rb +80 -0
- data/lib/openhab/core/actions/ping.rb +30 -0
- data/lib/openhab/core/actions/transformation.rb +32 -0
- data/lib/openhab/core/actions/voice.rb +36 -0
- data/lib/openhab/core/actions.rb +82 -0
- data/lib/openhab/core/dependency_tracking.rb +34 -0
- data/lib/openhab/core/dto/item_channel_link.rb +33 -0
- data/lib/openhab/core/dto/thing.rb +27 -0
- data/lib/openhab/core/dto.rb +11 -0
- data/lib/openhab/core/entity_lookup.rb +152 -70
- data/lib/openhab/core/events/abstract_event.rb +18 -0
- data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
- data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
- data/lib/openhab/core/events/item_command_event.rb +78 -0
- data/lib/openhab/core/events/item_event.rb +22 -0
- data/lib/openhab/core/events/item_state_changed_event.rb +75 -0
- data/lib/openhab/core/events/item_state_event.rb +79 -0
- data/lib/openhab/core/events/thing_status_info_event.rb +55 -0
- data/lib/openhab/core/events.rb +10 -0
- data/lib/openhab/core/items/accepted_data_types.rb +29 -0
- data/lib/openhab/core/items/color_item.rb +52 -0
- data/lib/openhab/core/items/contact_item.rb +52 -0
- data/lib/openhab/core/items/date_time_item.rb +59 -0
- data/lib/openhab/core/items/dimmer_item.rb +148 -0
- data/lib/openhab/core/items/generic_item.rb +292 -0
- data/lib/openhab/core/items/group_item.rb +176 -0
- data/lib/openhab/{dsl → core}/items/image_item.rb +35 -29
- data/lib/openhab/core/items/item.rb +273 -0
- data/lib/openhab/core/items/location_item.rb +34 -0
- data/lib/openhab/core/items/metadata/hash.rb +433 -0
- data/lib/openhab/core/items/metadata/namespace_hash.rb +475 -0
- data/lib/openhab/core/items/metadata/provider.rb +48 -0
- data/lib/openhab/core/items/metadata.rb +11 -0
- data/lib/openhab/core/items/number_item.rb +62 -0
- data/lib/openhab/core/items/numeric_item.rb +22 -0
- data/lib/openhab/core/items/persistence.rb +416 -0
- data/lib/openhab/core/items/player_item.rb +66 -0
- data/lib/openhab/core/items/provider.rb +44 -0
- data/lib/openhab/core/items/proxy.rb +136 -0
- data/lib/openhab/core/items/registry.rb +86 -0
- data/lib/openhab/core/items/rollershutter_item.rb +68 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +177 -0
- data/lib/openhab/core/items/semantics.rb +473 -0
- data/lib/openhab/core/items/state_storage.rb +53 -0
- data/lib/openhab/core/items/string_item.rb +28 -0
- data/lib/openhab/core/items/switch_item.rb +78 -0
- data/lib/openhab/core/items.rb +108 -0
- data/lib/openhab/{dsl → core}/lazy_array.rb +9 -3
- data/lib/openhab/core/profile_factory.rb +132 -0
- data/lib/openhab/core/provider.rb +230 -0
- data/lib/openhab/core/proxy.rb +130 -0
- data/lib/openhab/core/registry.rb +40 -0
- data/lib/openhab/core/rules/module.rb +26 -0
- data/lib/openhab/core/rules/provider.rb +25 -0
- data/lib/openhab/core/rules/registry.rb +76 -0
- data/lib/openhab/core/rules/rule.rb +150 -0
- data/lib/openhab/core/rules.rb +25 -0
- data/lib/openhab/core/script_handling.rb +78 -20
- data/lib/openhab/core/things/channel.rb +48 -0
- data/lib/openhab/core/things/channel_uid.rb +51 -0
- data/lib/openhab/core/things/item_channel_link.rb +33 -0
- data/lib/openhab/core/things/links/provider.rb +78 -0
- data/lib/openhab/core/things/profile_callback.rb +52 -0
- data/lib/openhab/core/things/provider.rb +29 -0
- data/lib/openhab/core/things/proxy.rb +87 -0
- data/lib/openhab/core/things/registry.rb +73 -0
- data/lib/openhab/core/things/thing.rb +194 -0
- data/lib/openhab/core/things.rb +22 -0
- data/lib/openhab/core/timer.rb +148 -0
- data/lib/openhab/{dsl → core}/types/comparable_type.rb +5 -3
- data/lib/openhab/{dsl → core}/types/date_time_type.rb +55 -127
- data/lib/openhab/{dsl → core}/types/decimal_type.rb +50 -48
- data/lib/openhab/{dsl → core}/types/hsb_type.rb +35 -83
- data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
- data/lib/openhab/core/types/next_previous_type.rb +34 -0
- data/lib/openhab/{dsl → core}/types/numeric_type.rb +20 -7
- data/lib/openhab/core/types/on_off_type.rb +46 -0
- data/lib/openhab/core/types/open_closed_type.rb +41 -0
- data/lib/openhab/{dsl → core}/types/percent_type.rb +19 -20
- data/lib/openhab/core/types/play_pause_type.rb +38 -0
- data/lib/openhab/core/types/point_type.rb +117 -0
- data/lib/openhab/core/types/quantity_type.rb +325 -0
- data/lib/openhab/core/types/raw_type.rb +26 -0
- data/lib/openhab/core/types/refresh_type.rb +27 -0
- data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
- data/lib/openhab/core/types/stop_move_type.rb +34 -0
- data/lib/openhab/{dsl → core}/types/string_type.rb +17 -28
- data/lib/openhab/{dsl → core}/types/type.rb +42 -40
- data/lib/openhab/core/types/un_def_type.rb +38 -0
- data/lib/openhab/core/types/up_down_type.rb +50 -0
- data/lib/openhab/core/types.rb +82 -0
- data/lib/openhab/{dsl → core}/uid.rb +4 -23
- data/lib/openhab/core/value_cache.rb +188 -0
- data/lib/openhab/core.rb +98 -0
- data/lib/openhab/core_ext/between.rb +32 -0
- data/lib/openhab/core_ext/ephemeris.rb +53 -0
- data/lib/openhab/core_ext/java/class.rb +34 -0
- data/lib/openhab/core_ext/java/duration.rb +142 -0
- data/lib/openhab/core_ext/java/list.rb +436 -0
- data/lib/openhab/core_ext/java/local_date.rb +104 -0
- data/lib/openhab/core_ext/java/local_time.rb +118 -0
- data/lib/openhab/core_ext/java/map.rb +66 -0
- data/lib/openhab/core_ext/java/month.rb +71 -0
- data/lib/openhab/core_ext/java/month_day.rb +119 -0
- data/lib/openhab/core_ext/java/period.rb +103 -0
- data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
- data/lib/openhab/core_ext/java/time.rb +62 -0
- data/lib/openhab/core_ext/java/unit.rb +15 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +213 -0
- data/lib/openhab/core_ext/ruby/array.rb +21 -0
- data/lib/openhab/core_ext/ruby/date.rb +96 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +55 -0
- data/lib/openhab/core_ext/ruby/module.rb +15 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +195 -0
- data/lib/openhab/core_ext/ruby/range.rb +70 -0
- data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
- data/lib/openhab/core_ext/ruby/time.rb +108 -0
- data/lib/openhab/core_ext.rb +18 -0
- data/lib/openhab/dsl/debouncer.rb +259 -0
- data/lib/openhab/dsl/events/watch_event.rb +18 -0
- data/lib/openhab/dsl/events.rb +9 -0
- data/lib/openhab/dsl/gems.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +578 -0
- data/lib/openhab/dsl/items/ensure.rb +73 -82
- data/lib/openhab/dsl/items/timed_command.rb +214 -159
- data/lib/openhab/dsl/rules/automation_rule.rb +126 -115
- data/lib/openhab/dsl/rules/builder.rb +1935 -0
- data/lib/openhab/dsl/rules/guard.rb +51 -114
- data/lib/openhab/dsl/rules/name_inference.rb +66 -25
- data/lib/openhab/dsl/rules/property.rb +48 -75
- data/lib/openhab/dsl/rules/rule_triggers.rb +22 -27
- data/lib/openhab/dsl/rules/terse.rb +58 -14
- data/lib/openhab/dsl/rules/triggers/changed.rb +48 -94
- data/lib/openhab/dsl/rules/triggers/channel.rb +9 -40
- data/lib/openhab/dsl/rules/triggers/command.rb +14 -63
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +34 -69
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +6 -14
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +48 -82
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +30 -47
- data/lib/openhab/dsl/rules/triggers/trigger.rb +7 -28
- data/lib/openhab/dsl/rules/triggers/updated.rb +21 -45
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +257 -102
- data/lib/openhab/dsl/rules/triggers.rb +12 -0
- data/lib/openhab/dsl/rules.rb +8 -0
- data/lib/openhab/dsl/things/builder.rb +299 -0
- data/lib/openhab/{core → dsl}/thread_local.rb +27 -17
- data/lib/openhab/dsl/timer_manager.rb +204 -0
- data/lib/openhab/dsl/version.rb +9 -0
- data/lib/openhab/dsl.rb +979 -0
- data/lib/openhab/log.rb +355 -0
- data/lib/openhab/osgi.rb +68 -0
- data/lib/openhab/rspec/configuration.rb +56 -0
- data/lib/openhab/rspec/example_group.rb +132 -0
- data/lib/openhab/rspec/helpers.rb +458 -0
- data/lib/openhab/rspec/hooks.rb +113 -0
- data/lib/openhab/rspec/jruby.rb +46 -0
- data/lib/openhab/rspec/karaf.rb +851 -0
- data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
- data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
- data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
- data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
- data/lib/openhab/rspec/mocks/persistence_service.rb +155 -0
- data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
- data/lib/openhab/rspec/mocks/space.rb +23 -0
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +63 -0
- data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
- data/lib/openhab/rspec/mocks/timer.rb +134 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +38 -0
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +15 -0
- data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
- data/lib/openhab/rspec/shell.rb +31 -0
- data/lib/openhab/rspec/suspend_rules.rb +50 -0
- data/lib/openhab/rspec.rb +26 -0
- data/lib/openhab/yard/base_helper.rb +19 -0
- data/lib/openhab/yard/cli/stats.rb +23 -0
- data/lib/openhab/yard/code_objects/group_object.rb +23 -0
- data/lib/openhab/yard/code_objects/java/base.rb +31 -0
- data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
- data/lib/openhab/yard/coderay.rb +17 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +58 -0
- data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +30 -0
- data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
- data/lib/openhab/yard/html_helper.rb +78 -0
- data/lib/openhab/yard/markdown_helper.rb +148 -0
- data/lib/openhab/yard/tags/constant_directive.rb +20 -0
- data/lib/openhab/yard/tags/group_directive.rb +24 -0
- data/lib/openhab/yard/tags/library.rb +3 -0
- data/lib/openhab/yard.rb +38 -0
- metadata +475 -106
- data/lib/openhab/core/item_proxy.rb +0 -29
- data/lib/openhab/core/load_path.rb +0 -19
- data/lib/openhab/core/openhab_setup.rb +0 -29
- data/lib/openhab/core/osgi.rb +0 -58
- data/lib/openhab/core/services.rb +0 -24
- data/lib/openhab/dsl/actions.rb +0 -114
- data/lib/openhab/dsl/between.rb +0 -25
- data/lib/openhab/dsl/channel.rb +0 -43
- data/lib/openhab/dsl/dsl.rb +0 -59
- data/lib/openhab/dsl/group.rb +0 -54
- data/lib/openhab/dsl/imports.rb +0 -21
- data/lib/openhab/dsl/items/color_item.rb +0 -76
- data/lib/openhab/dsl/items/comparable_item.rb +0 -62
- data/lib/openhab/dsl/items/contact_item.rb +0 -41
- data/lib/openhab/dsl/items/date_time_item.rb +0 -65
- data/lib/openhab/dsl/items/dimmer_item.rb +0 -65
- data/lib/openhab/dsl/items/generic_item.rb +0 -229
- data/lib/openhab/dsl/items/group_item.rb +0 -127
- data/lib/openhab/dsl/items/item_equality.rb +0 -59
- data/lib/openhab/dsl/items/item_registry.rb +0 -54
- data/lib/openhab/dsl/items/items.rb +0 -109
- data/lib/openhab/dsl/items/location_item.rb +0 -59
- data/lib/openhab/dsl/items/metadata.rb +0 -326
- data/lib/openhab/dsl/items/number_item.rb +0 -17
- data/lib/openhab/dsl/items/numeric_item.rb +0 -87
- data/lib/openhab/dsl/items/persistence.rb +0 -307
- data/lib/openhab/dsl/items/player_item.rb +0 -58
- data/lib/openhab/dsl/items/rollershutter_item.rb +0 -51
- data/lib/openhab/dsl/items/semantics/enumerable.rb +0 -91
- data/lib/openhab/dsl/items/semantics.rb +0 -227
- data/lib/openhab/dsl/items/string_item.rb +0 -51
- data/lib/openhab/dsl/items/switch_item.rb +0 -70
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +0 -39
- data/lib/openhab/dsl/monkey_patch/events/events.rb +0 -7
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +0 -85
- data/lib/openhab/dsl/monkey_patch/events/item_event.rb +0 -28
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +0 -61
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +0 -60
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +0 -33
- data/lib/openhab/dsl/monkey_patch/java/java.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/java/local_time.rb +0 -44
- data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +0 -50
- data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +0 -45
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -104
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -6
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +0 -47
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -61
- data/lib/openhab/dsl/openhab.rb +0 -30
- data/lib/openhab/dsl/persistence.rb +0 -27
- data/lib/openhab/dsl/rules/item_event.rb +0 -19
- data/lib/openhab/dsl/rules/rule.rb +0 -160
- data/lib/openhab/dsl/rules/rule_config.rb +0 -147
- data/lib/openhab/dsl/rules/triggers/generic.rb +0 -31
- data/lib/openhab/dsl/rules/triggers/triggers.rb +0 -11
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +0 -81
- data/lib/openhab/dsl/states.rb +0 -89
- data/lib/openhab/dsl/things.rb +0 -147
- data/lib/openhab/dsl/time/month_day.rb +0 -180
- data/lib/openhab/dsl/time/time_of_day.rb +0 -235
- data/lib/openhab/dsl/timers/manager.rb +0 -119
- data/lib/openhab/dsl/timers/reentrant_timer.rb +0 -38
- data/lib/openhab/dsl/timers/timer.rb +0 -132
- data/lib/openhab/dsl/timers.rb +0 -77
- data/lib/openhab/dsl/types/increase_decrease_type.rb +0 -23
- data/lib/openhab/dsl/types/next_previous_type.rb +0 -23
- data/lib/openhab/dsl/types/on_off_type.rb +0 -28
- data/lib/openhab/dsl/types/open_closed_type.rb +0 -29
- data/lib/openhab/dsl/types/play_pause_type.rb +0 -27
- data/lib/openhab/dsl/types/point_type.rb +0 -180
- data/lib/openhab/dsl/types/quantity_type.rb +0 -265
- data/lib/openhab/dsl/types/refresh_type.rb +0 -18
- data/lib/openhab/dsl/types/rewind_fastforward_type.rb +0 -33
- data/lib/openhab/dsl/types/stop_move_type.rb +0 -23
- data/lib/openhab/dsl/types/types.rb +0 -83
- data/lib/openhab/dsl/types/un_def_type.rb +0 -22
- data/lib/openhab/dsl/types/up_down_type.rb +0 -32
- data/lib/openhab/dsl/units.rb +0 -45
- data/lib/openhab/log/configuration.rb +0 -21
- data/lib/openhab/log/logger.rb +0 -282
- data/lib/openhab/version.rb +0 -9
- data/lib/openhab.rb +0 -36
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'numeric_item'
|
|
4
|
-
|
|
5
|
-
module OpenHAB
|
|
6
|
-
module DSL
|
|
7
|
-
#
|
|
8
|
-
# Patches OpenHAB items
|
|
9
|
-
#
|
|
10
|
-
module Items
|
|
11
|
-
java_import org.openhab.core.library.items.DimmerItem
|
|
12
|
-
|
|
13
|
-
# Alias class
|
|
14
|
-
::Dimmer = DimmerItem
|
|
15
|
-
|
|
16
|
-
# Adds methods to core OpenHAB DimmerItem type to make it more natural in
|
|
17
|
-
# Ruby
|
|
18
|
-
class DimmerItem < SwitchItem
|
|
19
|
-
include NumericItem
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# Dim the dimmer
|
|
23
|
-
#
|
|
24
|
-
# @param [Integer] amount to dim by
|
|
25
|
-
#
|
|
26
|
-
# @return [Integer] level target for dimmer
|
|
27
|
-
#
|
|
28
|
-
def dim(amount = 1)
|
|
29
|
-
target = [state&.-(amount), 0].compact.max
|
|
30
|
-
command(target)
|
|
31
|
-
target
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
# Brighten the dimmer
|
|
36
|
-
#
|
|
37
|
-
# @param [Integer] amount to brighten by
|
|
38
|
-
#
|
|
39
|
-
# @return [Integer] level target for dimmer
|
|
40
|
-
#
|
|
41
|
-
def brighten(amount = 1)
|
|
42
|
-
target = [state&.+(amount), 100].compact.min
|
|
43
|
-
command(target)
|
|
44
|
-
target
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @!method increase
|
|
48
|
-
# Send the +INCREASE+ command to the item
|
|
49
|
-
# @return [DimmerItem] +self+
|
|
50
|
-
|
|
51
|
-
# @!method decrease
|
|
52
|
-
# Send the +DECREASE+ command to the item
|
|
53
|
-
# @return [DimmerItem] +self+
|
|
54
|
-
|
|
55
|
-
# raw numbers translate directly to PercentType, not a DecimalType
|
|
56
|
-
# @!visibility private
|
|
57
|
-
def format_type(command)
|
|
58
|
-
return Types::PercentType.new(command) if command.is_a?(Numeric)
|
|
59
|
-
|
|
60
|
-
super
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'delegate'
|
|
4
|
-
require 'forwardable'
|
|
5
|
-
|
|
6
|
-
require_relative 'metadata'
|
|
7
|
-
require_relative 'persistence'
|
|
8
|
-
require_relative 'semantics'
|
|
9
|
-
|
|
10
|
-
require_relative 'item_equality'
|
|
11
|
-
|
|
12
|
-
module OpenHAB
|
|
13
|
-
module DSL
|
|
14
|
-
module Items
|
|
15
|
-
java_import org.openhab.core.items.GenericItem
|
|
16
|
-
|
|
17
|
-
# Adds methods to core OpenHAB GenericItem type to make it more natural in
|
|
18
|
-
# Ruby
|
|
19
|
-
#
|
|
20
|
-
# @see https://www.openhab.org/javadoc/latest/org/openhab/core/items/genericitem
|
|
21
|
-
class GenericItem
|
|
22
|
-
include Log
|
|
23
|
-
include ItemEquality
|
|
24
|
-
|
|
25
|
-
prepend Metadata
|
|
26
|
-
prepend Persistence
|
|
27
|
-
include Semantics
|
|
28
|
-
|
|
29
|
-
# rubocop:disable Naming/MethodName these mimic Java fields, which are
|
|
30
|
-
# actually methods
|
|
31
|
-
class << self
|
|
32
|
-
# manually define this, since the Java side doesn't
|
|
33
|
-
# @!visibility private
|
|
34
|
-
def ACCEPTED_COMMAND_TYPES
|
|
35
|
-
[org.openhab.core.types.RefreshType.java_class].freeze
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# manually define this, since the Java side doesn't
|
|
39
|
-
# @!visibility private
|
|
40
|
-
def ACCEPTED_DATA_TYPES
|
|
41
|
-
[org.openhab.core.types.UnDefType.java_class].freeze
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#
|
|
45
|
-
# Override to support ItemProxy
|
|
46
|
-
#
|
|
47
|
-
def ===(other)
|
|
48
|
-
other.instance_of?(self)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
# rubocop:enable Naming/MethodName
|
|
52
|
-
|
|
53
|
-
alias hash hash_code
|
|
54
|
-
|
|
55
|
-
# Get the raw item state.
|
|
56
|
-
#
|
|
57
|
-
# The state of the item, including possibly +NULL+ or +UNDEF+
|
|
58
|
-
#
|
|
59
|
-
# @return [Types::Type]
|
|
60
|
-
#
|
|
61
|
-
alias raw_state state
|
|
62
|
-
|
|
63
|
-
remove_method(:==)
|
|
64
|
-
|
|
65
|
-
#
|
|
66
|
-
# Send a command to this item
|
|
67
|
-
#
|
|
68
|
-
# @param [Types::Type] command to send to object
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
def command(command)
|
|
72
|
-
command = format_type_pre(command)
|
|
73
|
-
logger.trace "Sending Command #{command} to #{id}"
|
|
74
|
-
org.openhab.core.model.script.actions.BusEvent.sendCommand(self, command)
|
|
75
|
-
self
|
|
76
|
-
end
|
|
77
|
-
alias << command
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
# Send an update to this item
|
|
81
|
-
#
|
|
82
|
-
# @param [Types::Type] update the item
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
def update(update)
|
|
86
|
-
update = format_type_pre(update)
|
|
87
|
-
logger.trace "Sending Update #{update} to #{id}"
|
|
88
|
-
org.openhab.core.model.script.actions.BusEvent.postUpdate(self, update)
|
|
89
|
-
self
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
# Check if the item has a state (not +UNDEF+ or +NULL+)
|
|
94
|
-
#
|
|
95
|
-
# @return [Boolean]
|
|
96
|
-
#
|
|
97
|
-
def state?
|
|
98
|
-
!raw_state.is_a?(Types::UnDefType)
|
|
99
|
-
end
|
|
100
|
-
alias truthy? state?
|
|
101
|
-
|
|
102
|
-
#
|
|
103
|
-
# Get the item state
|
|
104
|
-
#
|
|
105
|
-
# @return [Types::Type, nil]
|
|
106
|
-
# OpenHAB item state if state is not +UNDEF+ or +NULL+, nil otherwise
|
|
107
|
-
#
|
|
108
|
-
def state
|
|
109
|
-
raw_state if state?
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
#
|
|
113
|
-
# Get an ID for the item, using the item label if set, otherwise item name
|
|
114
|
-
#
|
|
115
|
-
# @return [String] label if set otherwise name
|
|
116
|
-
#
|
|
117
|
-
def id
|
|
118
|
-
label || name
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
#
|
|
122
|
-
# Get the string representation of the state of the item
|
|
123
|
-
#
|
|
124
|
-
# @return [String] State of the item as a string
|
|
125
|
-
#
|
|
126
|
-
def to_s
|
|
127
|
-
raw_state.to_s # call the super state to include UNDEF/NULL
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
#
|
|
131
|
-
# Inspect the item
|
|
132
|
-
#
|
|
133
|
-
# @return [String] details of the item
|
|
134
|
-
#
|
|
135
|
-
def inspect
|
|
136
|
-
to_string
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
#
|
|
140
|
-
# Return all groups that this item is part of
|
|
141
|
-
#
|
|
142
|
-
# @return [Array<Group>] All groups that this item is part of
|
|
143
|
-
#
|
|
144
|
-
def groups
|
|
145
|
-
group_names.map { |name| Groups.groups[name] }.compact
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# Return the item's thing if this item is linked with a thing. If an item is linked to more than one thing,
|
|
149
|
-
# this method only returns the first thing.
|
|
150
|
-
#
|
|
151
|
-
# @return [Thing] The thing associated with this item or nil
|
|
152
|
-
def thing
|
|
153
|
-
all_linked_things.first
|
|
154
|
-
end
|
|
155
|
-
alias linked_thing thing
|
|
156
|
-
|
|
157
|
-
# Returns all of the item's linked things.
|
|
158
|
-
#
|
|
159
|
-
# @return [Array] An array of things or an empty array
|
|
160
|
-
def things
|
|
161
|
-
registry = OpenHAB::Core::OSGI.service('org.openhab.core.thing.link.ItemChannelLinkRegistry')
|
|
162
|
-
channels = registry.get_bound_channels(name).to_a
|
|
163
|
-
channels.map(&:thing_uid).uniq.map { |tuid| OpenHAB::DSL::Things.things[tuid] }
|
|
164
|
-
end
|
|
165
|
-
alias all_linked_things things
|
|
166
|
-
|
|
167
|
-
#
|
|
168
|
-
# Check equality without type conversion
|
|
169
|
-
#
|
|
170
|
-
# @return [Boolean] if the same Item is represented, without checking
|
|
171
|
-
# state
|
|
172
|
-
def eql?(other)
|
|
173
|
-
other.instance_of?(self.class) && hash == other.hash
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
#
|
|
177
|
-
# A method to indicate that item comparison is requested instead of state comparison
|
|
178
|
-
#
|
|
179
|
-
# Example: Item1.item == items['Item1'].item should return true
|
|
180
|
-
#
|
|
181
|
-
# See ItemEquality#==
|
|
182
|
-
#
|
|
183
|
-
def item
|
|
184
|
-
@item ||= GenericItemObject.new(self)
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# @!method null?
|
|
188
|
-
# Check if the item state == +NULL+
|
|
189
|
-
# @return [Boolean]
|
|
190
|
-
|
|
191
|
-
# @!method undef?
|
|
192
|
-
# Check if the item state == +UNDEF+
|
|
193
|
-
# @return [Boolean]
|
|
194
|
-
|
|
195
|
-
# @!method refresh
|
|
196
|
-
# Send the +REFRESH+ command to the item
|
|
197
|
-
# @return [GenericItem] +self+
|
|
198
|
-
|
|
199
|
-
# formats a {Types::Type} to send to the event bus
|
|
200
|
-
# @!visibility private
|
|
201
|
-
def format_type(command)
|
|
202
|
-
# actual Type types can be sent directly without conversion
|
|
203
|
-
return command if command.is_a?(Types::Type)
|
|
204
|
-
|
|
205
|
-
command.to_s
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
private
|
|
209
|
-
|
|
210
|
-
# convert items to their state before formatting, so that subclasses
|
|
211
|
-
# only have to deal with Types
|
|
212
|
-
def format_type_pre(command)
|
|
213
|
-
command = command.state if command.is_a?(GenericItem)
|
|
214
|
-
format_type(command)
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
# A helper class to flag that item comparison is wanted instead of state comparison
|
|
220
|
-
# It is used by ItemEquality#===
|
|
221
|
-
class GenericItemObject < SimpleDelegator
|
|
222
|
-
extend Forwardable
|
|
223
|
-
include Log
|
|
224
|
-
include OpenHAB::DSL::Items::ItemEquality
|
|
225
|
-
|
|
226
|
-
def_delegator :__getobj__, :instance_of? # instance_of? is used by GenericItem#eql? to check for item equality
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'comparable_item'
|
|
4
|
-
require 'openhab/dsl/lazy_array'
|
|
5
|
-
|
|
6
|
-
module OpenHAB
|
|
7
|
-
module DSL
|
|
8
|
-
module Items
|
|
9
|
-
java_import org.openhab.core.items.GroupItem
|
|
10
|
-
|
|
11
|
-
# Adds methods to core OpenHAB GroupItem type to make it more natural in
|
|
12
|
-
# Ruby
|
|
13
|
-
class GroupItem < GenericItem
|
|
14
|
-
#
|
|
15
|
-
# Class for indicating to triggers that a group trigger should be used
|
|
16
|
-
#
|
|
17
|
-
class GroupMembers
|
|
18
|
-
include LazyArray
|
|
19
|
-
|
|
20
|
-
# @return [GroupItem]
|
|
21
|
-
attr_reader :group
|
|
22
|
-
|
|
23
|
-
# @!visibility private
|
|
24
|
-
def initialize(group_item)
|
|
25
|
-
@group = group_item
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Explicit conversion to Array
|
|
29
|
-
#
|
|
30
|
-
# @return [Array]
|
|
31
|
-
def to_a
|
|
32
|
-
group.get_members.map { |i| ::OpenHAB::Core::ItemProxy.new(i) }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Name of the group
|
|
36
|
-
#
|
|
37
|
-
# @return [String]
|
|
38
|
-
def name
|
|
39
|
-
group.name
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
alias << command
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
include Enumerable
|
|
46
|
-
include ComparableItem
|
|
47
|
-
prepend Semantics # make Semantics#points take precedence over Enumerable#points for GroupItem
|
|
48
|
-
|
|
49
|
-
remove_method :==
|
|
50
|
-
|
|
51
|
-
# Override Enumerable because we want to send them to the base item if possible
|
|
52
|
-
#
|
|
53
|
-
# @return [GroupMembers] +self+
|
|
54
|
-
%i[command update].each do |method|
|
|
55
|
-
define_method(method) do |command|
|
|
56
|
-
return base_item.__send__(method, command) if base_item
|
|
57
|
-
|
|
58
|
-
super(command)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
#
|
|
63
|
-
# Get an Array-like object representing the members of the group
|
|
64
|
-
#
|
|
65
|
-
# @return [GroupMembers]
|
|
66
|
-
#
|
|
67
|
-
def members
|
|
68
|
-
GroupMembers.new(self)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# @deprecated
|
|
72
|
-
alias items members
|
|
73
|
-
|
|
74
|
-
#
|
|
75
|
-
# Iterates through the direct members of the Group
|
|
76
|
-
#
|
|
77
|
-
def each(&block)
|
|
78
|
-
members.each(&block)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
#
|
|
82
|
-
# Get all members of the group recursively. Optionally filter the items to only return
|
|
83
|
-
# Groups or regular Items
|
|
84
|
-
#
|
|
85
|
-
# @param [Symbol] filter Either +:groups+ or +:items+
|
|
86
|
-
#
|
|
87
|
-
# @return [Array] An Array containing all descendants of the Group, optionally filtered
|
|
88
|
-
#
|
|
89
|
-
def all_members(filter = nil, &block)
|
|
90
|
-
filter = nil if filter == :items
|
|
91
|
-
raise ArgumentError, 'filter must be :groups or :items' unless [:groups, nil].include?(filter)
|
|
92
|
-
|
|
93
|
-
block = ->(i) { i.is_a?(GroupItem) } if filter
|
|
94
|
-
|
|
95
|
-
if block
|
|
96
|
-
get_members(&block).to_a
|
|
97
|
-
else
|
|
98
|
-
get_all_members.to_a
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Delegate missing methods to +base_item+ if possible
|
|
103
|
-
def method_missing(method, *args, &block)
|
|
104
|
-
return base_item.__send__(method, *args, &block) if base_item.respond_to?(method)
|
|
105
|
-
|
|
106
|
-
super
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# @!visibility private
|
|
110
|
-
def respond_to_missing?(method, include_private = false)
|
|
111
|
-
return true if base_item.respond_to?(method)
|
|
112
|
-
|
|
113
|
-
super
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# Is this ever called?
|
|
117
|
-
# give the base item type a chance to format commands
|
|
118
|
-
# @!visibility private
|
|
119
|
-
def format_type(command)
|
|
120
|
-
return super unless base_item
|
|
121
|
-
|
|
122
|
-
base_item.format_type(command)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OpenHAB
|
|
4
|
-
module DSL
|
|
5
|
-
module Items
|
|
6
|
-
# Shared method for checking item equality by delegating to state
|
|
7
|
-
module ItemEquality
|
|
8
|
-
# Check equality, with type conversions
|
|
9
|
-
#
|
|
10
|
-
# @param [GenericItem, Types::Type, Object] other object to
|
|
11
|
-
# compare to
|
|
12
|
-
#
|
|
13
|
-
# If this item is +NULL+ or +UNDEF+, and +other+ is nil, they are
|
|
14
|
-
# considered equal
|
|
15
|
-
#
|
|
16
|
-
# If this item is +NULL+ or +UNDEF+, and other is a {GenericItem}, they
|
|
17
|
-
# are only considered equal if the other item is in the exact same
|
|
18
|
-
# state (i.e. +NULL+ != +UNDEF+)
|
|
19
|
-
#
|
|
20
|
-
# Otherwise, the state of this item is compared with +other+
|
|
21
|
-
#
|
|
22
|
-
# @return [Boolean]
|
|
23
|
-
#
|
|
24
|
-
def ==(other)
|
|
25
|
-
logger.trace { "ItemEquality#== (#{self.class}) #{self} == #{other} (#{other.class})" }
|
|
26
|
-
return eql?(other) if generic_item_object?(other)
|
|
27
|
-
return true if equal?(other) || eql?(other)
|
|
28
|
-
return true if !state? && other.nil?
|
|
29
|
-
|
|
30
|
-
return raw_state == other.raw_state if other.is_a?(GenericItem)
|
|
31
|
-
|
|
32
|
-
state == other
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
#
|
|
36
|
-
# Check item object equality for grep
|
|
37
|
-
#
|
|
38
|
-
def ===(other)
|
|
39
|
-
logger.trace { "ItemEquality#=== (#{self.class}) #{self} == #{other} (#{other.class})" }
|
|
40
|
-
eql?(other)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
# Determines if an object equality check is required, based on whether
|
|
47
|
-
# either operand is a GenericItemObject
|
|
48
|
-
#
|
|
49
|
-
# @param [Object] other
|
|
50
|
-
#
|
|
51
|
-
# @return [Boolean]
|
|
52
|
-
#
|
|
53
|
-
def generic_item_object?(other)
|
|
54
|
-
other.is_a?(OpenHAB::DSL::GenericItemObject) || is_a?(OpenHAB::DSL::GenericItemObject)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'singleton'
|
|
4
|
-
|
|
5
|
-
require 'openhab/core/entity_lookup'
|
|
6
|
-
require 'openhab/dsl/lazy_array'
|
|
7
|
-
|
|
8
|
-
module OpenHAB
|
|
9
|
-
module DSL
|
|
10
|
-
module Items
|
|
11
|
-
module_function
|
|
12
|
-
|
|
13
|
-
# Fetches all non-group items from the item registry
|
|
14
|
-
# @return [ItemRegistry]
|
|
15
|
-
def items
|
|
16
|
-
OpenHAB::DSL::Support::ItemRegistry.instance
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Provide supporting objects for DSL functions
|
|
21
|
-
module Support
|
|
22
|
-
#
|
|
23
|
-
# Provides access to all OpenHAB items, and acts like an array.
|
|
24
|
-
#
|
|
25
|
-
class ItemRegistry
|
|
26
|
-
include LazyArray
|
|
27
|
-
include Singleton
|
|
28
|
-
|
|
29
|
-
# Fetches the named item from the the ItemRegistry
|
|
30
|
-
# @param [String] name
|
|
31
|
-
# @return [GenericItem] Item from registry, nil if item missing or requested item is a Group Type
|
|
32
|
-
def [](name)
|
|
33
|
-
OpenHAB::Core::EntityLookup.lookup_item(name)
|
|
34
|
-
rescue org.openhab.core.items.ItemNotFoundException
|
|
35
|
-
nil
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Returns true if the given item name exists
|
|
39
|
-
# @param name [String] Item name to check
|
|
40
|
-
# @return [Boolean] true if the item exists, false otherwise
|
|
41
|
-
def include?(name)
|
|
42
|
-
!$ir.getItems(name).empty?
|
|
43
|
-
end
|
|
44
|
-
alias key? include?
|
|
45
|
-
|
|
46
|
-
# Explicit conversion to array
|
|
47
|
-
# @return [Array]
|
|
48
|
-
def to_a
|
|
49
|
-
$ir.items.map { |item| OpenHAB::Core::ItemProxy.new(item) }
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'openhab/dsl/monkey_patch/events/item_command'
|
|
4
|
-
require 'openhab/dsl/types/types'
|
|
5
|
-
|
|
6
|
-
require_relative 'item_registry'
|
|
7
|
-
|
|
8
|
-
require_relative 'generic_item'
|
|
9
|
-
require_relative 'switch_item'
|
|
10
|
-
require_relative 'date_time_item'
|
|
11
|
-
require_relative 'dimmer_item'
|
|
12
|
-
require_relative 'color_item'
|
|
13
|
-
require_relative 'contact_item'
|
|
14
|
-
require_relative 'group_item'
|
|
15
|
-
require_relative 'image_item'
|
|
16
|
-
require_relative 'location_item'
|
|
17
|
-
require_relative 'number_item'
|
|
18
|
-
require_relative 'player_item'
|
|
19
|
-
require_relative 'rollershutter_item'
|
|
20
|
-
require_relative 'string_item'
|
|
21
|
-
|
|
22
|
-
require_relative 'ensure'
|
|
23
|
-
require_relative 'timed_command'
|
|
24
|
-
|
|
25
|
-
module OpenHAB
|
|
26
|
-
module DSL
|
|
27
|
-
# Contains all OpenHAB *Item classes, as well as associated support
|
|
28
|
-
# modules
|
|
29
|
-
module Items
|
|
30
|
-
include OpenHAB::Log
|
|
31
|
-
|
|
32
|
-
class << self
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
# takes an array of Type java classes and returns
|
|
36
|
-
# all the Enum values, in a flat array
|
|
37
|
-
def values_for_enums(enums)
|
|
38
|
-
enums.map(&:ruby_class)
|
|
39
|
-
.select { |k| k < java.lang.Enum }
|
|
40
|
-
.flat_map(&:values)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# define predicates for checking if an item is in one of the Enum states
|
|
44
|
-
def def_predicate_methods(klass)
|
|
45
|
-
values_for_enums(klass.ACCEPTED_DATA_TYPES).each do |state|
|
|
46
|
-
_command_predicate, state_predicate = OpenHAB::DSL::PREDICATE_ALIASES[state.to_s]
|
|
47
|
-
next if klass.instance_methods.include?(state_predicate)
|
|
48
|
-
|
|
49
|
-
logger.trace("Defining #{klass}##{state_predicate} for #{state}")
|
|
50
|
-
klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
51
|
-
def #{state_predicate} # def on?
|
|
52
|
-
raw_state == #{state} # raw_state == ON
|
|
53
|
-
end # end
|
|
54
|
-
RUBY
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# defined methods for commanding an item to one of the Enum states
|
|
59
|
-
# as well as predicates for if an ItemCommandEvent is one of those commands
|
|
60
|
-
def def_command_methods(klass) # rubocop:disable Metrics method has single purpose
|
|
61
|
-
values_for_enums(klass.ACCEPTED_COMMAND_TYPES).each do |value|
|
|
62
|
-
command = OpenHAB::DSL::COMMAND_ALIASES[value.to_s]
|
|
63
|
-
next if klass.instance_methods.include?(command)
|
|
64
|
-
|
|
65
|
-
logger.trace("Defining #{klass}##{command} for #{value}")
|
|
66
|
-
klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
67
|
-
def #{command}(for: nil, on_expire: nil, &block) # def on(for: nil, on_expire: nil, &block )
|
|
68
|
-
command(#{value}, for: binding.local_variable_get(:for), on_expire: on_expire, &block) # command(ON, for: nil, expire: nil, &block)
|
|
69
|
-
end # end
|
|
70
|
-
RUBY
|
|
71
|
-
|
|
72
|
-
logger.trace("Defining Enumerable##{command} for #{value}")
|
|
73
|
-
Enumerable.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
74
|
-
def #{command} # def on
|
|
75
|
-
each(&:#{command}) # each(&:on)
|
|
76
|
-
end # end
|
|
77
|
-
RUBY
|
|
78
|
-
|
|
79
|
-
# Override the inherited methods from Enumerable and send it to the base_item
|
|
80
|
-
GroupItem.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
81
|
-
def #{command} # def on
|
|
82
|
-
method_missing(:#{command}) # method_missing(:on)
|
|
83
|
-
end # end
|
|
84
|
-
RUBY
|
|
85
|
-
|
|
86
|
-
logger.trace("Defining ItemCommandEvent##{command}? for #{value}")
|
|
87
|
-
MonkeyPatch::Events::ItemCommandEvent.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
88
|
-
def #{command}? # def refresh?
|
|
89
|
-
command == #{value} # command == REFRESH
|
|
90
|
-
end # end
|
|
91
|
-
RUBY
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# sort classes by hierarchy so we define methods on parent classes first
|
|
97
|
-
constants.map { |c| const_get(c) }
|
|
98
|
-
.grep(Module)
|
|
99
|
-
.select { |k| k <= GenericItem && k != GroupItem && k != StringItem }
|
|
100
|
-
.sort { |a, b| a < b ? 1 : -1 }
|
|
101
|
-
.each do |klass|
|
|
102
|
-
klass.field_reader :ACCEPTED_COMMAND_TYPES, :ACCEPTED_DATA_TYPES unless klass == GenericItem
|
|
103
|
-
|
|
104
|
-
def_predicate_methods(klass)
|
|
105
|
-
def_command_methods(klass)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'forwardable'
|
|
4
|
-
|
|
5
|
-
require_relative 'comparable_item'
|
|
6
|
-
require 'openhab/dsl/types/point_type'
|
|
7
|
-
|
|
8
|
-
module OpenHAB
|
|
9
|
-
module DSL
|
|
10
|
-
module Items
|
|
11
|
-
java_import org.openhab.core.library.items.LocationItem
|
|
12
|
-
|
|
13
|
-
# Adds methods to core OpenHAB NumberItem type to make it more natural in
|
|
14
|
-
# Ruby
|
|
15
|
-
class LocationItem < GenericItem
|
|
16
|
-
extend Forwardable
|
|
17
|
-
include ComparableItem
|
|
18
|
-
|
|
19
|
-
# !@visibility private
|
|
20
|
-
def ==(other)
|
|
21
|
-
# need to check if we're referring to the same item before
|
|
22
|
-
# forwarding to <=> (and thus checking equality with state)
|
|
23
|
-
return true if equal?(other) || eql?(other)
|
|
24
|
-
|
|
25
|
-
super
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Support conversion to location items from a hash
|
|
29
|
-
# @!visibility private
|
|
30
|
-
def format_type(command)
|
|
31
|
-
return PointType.new(command.to_hash) if command.respond_to?(:to_hash)
|
|
32
|
-
|
|
33
|
-
super
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Type Coercion
|
|
37
|
-
#
|
|
38
|
-
# Coerce object to a PointType
|
|
39
|
-
#
|
|
40
|
-
# @param [Types::PointType, String] other object to coerce to a
|
|
41
|
-
# PointType
|
|
42
|
-
#
|
|
43
|
-
# @return [[Types::PointType, Types::PointType]]
|
|
44
|
-
#
|
|
45
|
-
def coerce(other)
|
|
46
|
-
logger.trace("Coercing #{self} as a request from #{other.class}")
|
|
47
|
-
return [other, nil] unless state?
|
|
48
|
-
return [other, state] if other.is_a?(Types::PointType) || other.respond_to?(:to_str)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# OpenHAB has this method, but it _only_ accepts PointType, so remove it and delegate
|
|
52
|
-
remove_method :distance_from
|
|
53
|
-
|
|
54
|
-
# any method that exists on {Types::PointType} gets forwarded to +state+
|
|
55
|
-
delegate (Types::PointType.instance_methods - instance_methods) => :state
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|