openhab-scripting 4.47.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/actions/audio.rb +47 -0
- data/lib/openhab/core/actions/ephemeris.rb +39 -0
- data/lib/openhab/core/actions/exec.rb +51 -0
- data/lib/openhab/core/actions/http.rb +80 -0
- data/lib/openhab/core/actions/ping.rb +30 -0
- data/lib/openhab/core/actions/transformation.rb +32 -0
- data/lib/openhab/core/actions/voice.rb +36 -0
- data/lib/openhab/core/actions.rb +82 -0
- data/lib/openhab/core/dependency_tracking.rb +34 -0
- data/lib/openhab/core/dto/item_channel_link.rb +33 -0
- data/lib/openhab/core/dto/thing.rb +27 -0
- data/lib/openhab/core/dto.rb +11 -0
- data/lib/openhab/core/entity_lookup.rb +152 -70
- data/lib/openhab/core/events/abstract_event.rb +18 -0
- data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
- data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
- data/lib/openhab/core/events/item_command_event.rb +78 -0
- data/lib/openhab/core/events/item_event.rb +22 -0
- data/lib/openhab/core/events/item_state_changed_event.rb +75 -0
- data/lib/openhab/core/events/item_state_event.rb +79 -0
- data/lib/openhab/core/events/thing_status_info_event.rb +55 -0
- data/lib/openhab/core/events.rb +10 -0
- data/lib/openhab/core/items/accepted_data_types.rb +29 -0
- data/lib/openhab/core/items/color_item.rb +52 -0
- data/lib/openhab/core/items/contact_item.rb +52 -0
- data/lib/openhab/core/items/date_time_item.rb +59 -0
- data/lib/openhab/core/items/dimmer_item.rb +148 -0
- data/lib/openhab/core/items/generic_item.rb +292 -0
- data/lib/openhab/core/items/group_item.rb +176 -0
- data/lib/openhab/{dsl → core}/items/image_item.rb +35 -29
- data/lib/openhab/core/items/item.rb +273 -0
- data/lib/openhab/core/items/location_item.rb +34 -0
- data/lib/openhab/core/items/metadata/hash.rb +433 -0
- data/lib/openhab/core/items/metadata/namespace_hash.rb +475 -0
- data/lib/openhab/core/items/metadata/provider.rb +48 -0
- data/lib/openhab/core/items/metadata.rb +11 -0
- data/lib/openhab/core/items/number_item.rb +62 -0
- data/lib/openhab/core/items/numeric_item.rb +22 -0
- data/lib/openhab/core/items/persistence.rb +416 -0
- data/lib/openhab/core/items/player_item.rb +66 -0
- data/lib/openhab/core/items/provider.rb +44 -0
- data/lib/openhab/core/items/proxy.rb +136 -0
- data/lib/openhab/core/items/registry.rb +86 -0
- data/lib/openhab/core/items/rollershutter_item.rb +68 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +177 -0
- data/lib/openhab/core/items/semantics.rb +473 -0
- data/lib/openhab/core/items/state_storage.rb +53 -0
- data/lib/openhab/core/items/string_item.rb +28 -0
- data/lib/openhab/core/items/switch_item.rb +78 -0
- data/lib/openhab/core/items.rb +108 -0
- data/lib/openhab/{dsl → core}/lazy_array.rb +9 -3
- data/lib/openhab/core/profile_factory.rb +132 -0
- data/lib/openhab/core/provider.rb +230 -0
- data/lib/openhab/core/proxy.rb +130 -0
- data/lib/openhab/core/registry.rb +40 -0
- data/lib/openhab/core/rules/module.rb +26 -0
- data/lib/openhab/core/rules/provider.rb +25 -0
- data/lib/openhab/core/rules/registry.rb +76 -0
- data/lib/openhab/core/rules/rule.rb +150 -0
- data/lib/openhab/core/rules.rb +25 -0
- data/lib/openhab/core/script_handling.rb +78 -20
- data/lib/openhab/core/things/channel.rb +48 -0
- data/lib/openhab/core/things/channel_uid.rb +51 -0
- data/lib/openhab/core/things/item_channel_link.rb +33 -0
- data/lib/openhab/core/things/links/provider.rb +78 -0
- data/lib/openhab/core/things/profile_callback.rb +52 -0
- data/lib/openhab/core/things/provider.rb +29 -0
- data/lib/openhab/core/things/proxy.rb +87 -0
- data/lib/openhab/core/things/registry.rb +73 -0
- data/lib/openhab/core/things/thing.rb +194 -0
- data/lib/openhab/core/things.rb +22 -0
- data/lib/openhab/core/timer.rb +148 -0
- data/lib/openhab/{dsl → core}/types/comparable_type.rb +5 -3
- data/lib/openhab/{dsl → core}/types/date_time_type.rb +55 -127
- data/lib/openhab/{dsl → core}/types/decimal_type.rb +50 -48
- data/lib/openhab/{dsl → core}/types/hsb_type.rb +35 -83
- data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
- data/lib/openhab/core/types/next_previous_type.rb +34 -0
- data/lib/openhab/{dsl → core}/types/numeric_type.rb +20 -7
- data/lib/openhab/core/types/on_off_type.rb +46 -0
- data/lib/openhab/core/types/open_closed_type.rb +41 -0
- data/lib/openhab/{dsl → core}/types/percent_type.rb +19 -20
- data/lib/openhab/core/types/play_pause_type.rb +38 -0
- data/lib/openhab/core/types/point_type.rb +117 -0
- data/lib/openhab/core/types/quantity_type.rb +325 -0
- data/lib/openhab/core/types/raw_type.rb +26 -0
- data/lib/openhab/core/types/refresh_type.rb +27 -0
- data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
- data/lib/openhab/core/types/stop_move_type.rb +34 -0
- data/lib/openhab/{dsl → core}/types/string_type.rb +17 -28
- data/lib/openhab/{dsl → core}/types/type.rb +42 -40
- data/lib/openhab/core/types/un_def_type.rb +38 -0
- data/lib/openhab/core/types/up_down_type.rb +50 -0
- data/lib/openhab/core/types.rb +82 -0
- data/lib/openhab/{dsl → core}/uid.rb +4 -23
- data/lib/openhab/core/value_cache.rb +188 -0
- data/lib/openhab/core.rb +98 -0
- data/lib/openhab/core_ext/between.rb +32 -0
- data/lib/openhab/core_ext/ephemeris.rb +53 -0
- data/lib/openhab/core_ext/java/class.rb +34 -0
- data/lib/openhab/core_ext/java/duration.rb +142 -0
- data/lib/openhab/core_ext/java/list.rb +436 -0
- data/lib/openhab/core_ext/java/local_date.rb +104 -0
- data/lib/openhab/core_ext/java/local_time.rb +118 -0
- data/lib/openhab/core_ext/java/map.rb +66 -0
- data/lib/openhab/core_ext/java/month.rb +71 -0
- data/lib/openhab/core_ext/java/month_day.rb +119 -0
- data/lib/openhab/core_ext/java/period.rb +103 -0
- data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
- data/lib/openhab/core_ext/java/time.rb +62 -0
- data/lib/openhab/core_ext/java/unit.rb +15 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +213 -0
- data/lib/openhab/core_ext/ruby/array.rb +21 -0
- data/lib/openhab/core_ext/ruby/date.rb +96 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +55 -0
- data/lib/openhab/core_ext/ruby/module.rb +15 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +195 -0
- data/lib/openhab/core_ext/ruby/range.rb +70 -0
- data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
- data/lib/openhab/core_ext/ruby/time.rb +108 -0
- data/lib/openhab/core_ext.rb +18 -0
- data/lib/openhab/dsl/debouncer.rb +259 -0
- data/lib/openhab/dsl/events/watch_event.rb +18 -0
- data/lib/openhab/dsl/events.rb +9 -0
- data/lib/openhab/dsl/gems.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +578 -0
- data/lib/openhab/dsl/items/ensure.rb +73 -82
- data/lib/openhab/dsl/items/timed_command.rb +214 -159
- data/lib/openhab/dsl/rules/automation_rule.rb +126 -115
- data/lib/openhab/dsl/rules/builder.rb +1935 -0
- data/lib/openhab/dsl/rules/guard.rb +51 -114
- data/lib/openhab/dsl/rules/name_inference.rb +66 -25
- data/lib/openhab/dsl/rules/property.rb +48 -75
- data/lib/openhab/dsl/rules/rule_triggers.rb +22 -27
- data/lib/openhab/dsl/rules/terse.rb +58 -14
- data/lib/openhab/dsl/rules/triggers/changed.rb +48 -94
- data/lib/openhab/dsl/rules/triggers/channel.rb +9 -40
- data/lib/openhab/dsl/rules/triggers/command.rb +14 -63
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +34 -69
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +6 -14
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +48 -82
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +30 -47
- data/lib/openhab/dsl/rules/triggers/trigger.rb +7 -28
- data/lib/openhab/dsl/rules/triggers/updated.rb +21 -45
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +257 -102
- data/lib/openhab/dsl/rules/triggers.rb +12 -0
- data/lib/openhab/dsl/rules.rb +8 -0
- data/lib/openhab/dsl/things/builder.rb +299 -0
- data/lib/openhab/{core → dsl}/thread_local.rb +27 -17
- data/lib/openhab/dsl/timer_manager.rb +204 -0
- data/lib/openhab/dsl/version.rb +9 -0
- data/lib/openhab/dsl.rb +979 -0
- data/lib/openhab/log.rb +355 -0
- data/lib/openhab/osgi.rb +68 -0
- data/lib/openhab/rspec/configuration.rb +56 -0
- data/lib/openhab/rspec/example_group.rb +132 -0
- data/lib/openhab/rspec/helpers.rb +458 -0
- data/lib/openhab/rspec/hooks.rb +113 -0
- data/lib/openhab/rspec/jruby.rb +46 -0
- data/lib/openhab/rspec/karaf.rb +851 -0
- data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
- data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
- data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
- data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
- data/lib/openhab/rspec/mocks/persistence_service.rb +155 -0
- data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
- data/lib/openhab/rspec/mocks/space.rb +23 -0
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +63 -0
- data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
- data/lib/openhab/rspec/mocks/timer.rb +134 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +38 -0
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +15 -0
- data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
- data/lib/openhab/rspec/shell.rb +31 -0
- data/lib/openhab/rspec/suspend_rules.rb +50 -0
- data/lib/openhab/rspec.rb +26 -0
- data/lib/openhab/yard/base_helper.rb +19 -0
- data/lib/openhab/yard/cli/stats.rb +23 -0
- data/lib/openhab/yard/code_objects/group_object.rb +23 -0
- data/lib/openhab/yard/code_objects/java/base.rb +31 -0
- data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
- data/lib/openhab/yard/coderay.rb +17 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +58 -0
- data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +30 -0
- data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
- data/lib/openhab/yard/html_helper.rb +78 -0
- data/lib/openhab/yard/markdown_helper.rb +148 -0
- data/lib/openhab/yard/tags/constant_directive.rb +20 -0
- data/lib/openhab/yard/tags/group_directive.rb +24 -0
- data/lib/openhab/yard/tags/library.rb +3 -0
- data/lib/openhab/yard.rb +38 -0
- metadata +475 -106
- data/lib/openhab/core/item_proxy.rb +0 -29
- data/lib/openhab/core/load_path.rb +0 -19
- data/lib/openhab/core/openhab_setup.rb +0 -29
- data/lib/openhab/core/osgi.rb +0 -58
- data/lib/openhab/core/services.rb +0 -24
- data/lib/openhab/dsl/actions.rb +0 -114
- data/lib/openhab/dsl/between.rb +0 -25
- data/lib/openhab/dsl/channel.rb +0 -43
- data/lib/openhab/dsl/dsl.rb +0 -59
- data/lib/openhab/dsl/group.rb +0 -54
- data/lib/openhab/dsl/imports.rb +0 -21
- data/lib/openhab/dsl/items/color_item.rb +0 -76
- data/lib/openhab/dsl/items/comparable_item.rb +0 -62
- data/lib/openhab/dsl/items/contact_item.rb +0 -41
- data/lib/openhab/dsl/items/date_time_item.rb +0 -65
- data/lib/openhab/dsl/items/dimmer_item.rb +0 -65
- data/lib/openhab/dsl/items/generic_item.rb +0 -229
- data/lib/openhab/dsl/items/group_item.rb +0 -127
- data/lib/openhab/dsl/items/item_equality.rb +0 -59
- data/lib/openhab/dsl/items/item_registry.rb +0 -54
- data/lib/openhab/dsl/items/items.rb +0 -109
- data/lib/openhab/dsl/items/location_item.rb +0 -59
- data/lib/openhab/dsl/items/metadata.rb +0 -326
- data/lib/openhab/dsl/items/number_item.rb +0 -17
- data/lib/openhab/dsl/items/numeric_item.rb +0 -87
- data/lib/openhab/dsl/items/persistence.rb +0 -307
- data/lib/openhab/dsl/items/player_item.rb +0 -58
- data/lib/openhab/dsl/items/rollershutter_item.rb +0 -51
- data/lib/openhab/dsl/items/semantics/enumerable.rb +0 -91
- data/lib/openhab/dsl/items/semantics.rb +0 -227
- data/lib/openhab/dsl/items/string_item.rb +0 -51
- data/lib/openhab/dsl/items/switch_item.rb +0 -70
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +0 -39
- data/lib/openhab/dsl/monkey_patch/events/events.rb +0 -7
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +0 -85
- data/lib/openhab/dsl/monkey_patch/events/item_event.rb +0 -28
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +0 -61
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +0 -60
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +0 -33
- data/lib/openhab/dsl/monkey_patch/java/java.rb +0 -4
- data/lib/openhab/dsl/monkey_patch/java/local_time.rb +0 -44
- data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +0 -50
- data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +0 -45
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -104
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -6
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +0 -47
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -61
- data/lib/openhab/dsl/openhab.rb +0 -30
- data/lib/openhab/dsl/persistence.rb +0 -27
- data/lib/openhab/dsl/rules/item_event.rb +0 -19
- data/lib/openhab/dsl/rules/rule.rb +0 -160
- data/lib/openhab/dsl/rules/rule_config.rb +0 -147
- data/lib/openhab/dsl/rules/triggers/generic.rb +0 -31
- data/lib/openhab/dsl/rules/triggers/triggers.rb +0 -11
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +0 -81
- data/lib/openhab/dsl/states.rb +0 -89
- data/lib/openhab/dsl/things.rb +0 -147
- data/lib/openhab/dsl/time/month_day.rb +0 -180
- data/lib/openhab/dsl/time/time_of_day.rb +0 -235
- data/lib/openhab/dsl/timers/manager.rb +0 -119
- data/lib/openhab/dsl/timers/reentrant_timer.rb +0 -38
- data/lib/openhab/dsl/timers/timer.rb +0 -132
- data/lib/openhab/dsl/timers.rb +0 -77
- data/lib/openhab/dsl/types/increase_decrease_type.rb +0 -23
- data/lib/openhab/dsl/types/next_previous_type.rb +0 -23
- data/lib/openhab/dsl/types/on_off_type.rb +0 -28
- data/lib/openhab/dsl/types/open_closed_type.rb +0 -29
- data/lib/openhab/dsl/types/play_pause_type.rb +0 -27
- data/lib/openhab/dsl/types/point_type.rb +0 -180
- data/lib/openhab/dsl/types/quantity_type.rb +0 -265
- data/lib/openhab/dsl/types/refresh_type.rb +0 -18
- data/lib/openhab/dsl/types/rewind_fastforward_type.rb +0 -33
- data/lib/openhab/dsl/types/stop_move_type.rb +0 -23
- data/lib/openhab/dsl/types/types.rb +0 -83
- data/lib/openhab/dsl/types/un_def_type.rb +0 -22
- data/lib/openhab/dsl/types/up_down_type.rb +0 -32
- data/lib/openhab/dsl/units.rb +0 -45
- data/lib/openhab/log/configuration.rb +0 -21
- data/lib/openhab/log/logger.rb +0 -282
- data/lib/openhab/version.rb +0 -9
- data/lib/openhab.rb +0 -38
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
module Types
|
6
|
-
UpDownType = org.openhab.core.library.types.UpDownType
|
7
|
-
|
8
|
-
# Adds methods to core OpenHAB UpDownType to make it more natural in Ruby
|
9
|
-
class UpDownType
|
10
|
-
# @!parse include Type
|
11
|
-
|
12
|
-
# @!method up?
|
13
|
-
# Check if == +UP+
|
14
|
-
# @return [Boolean]
|
15
|
-
|
16
|
-
# @!method down?
|
17
|
-
# Check if == +DOWN+
|
18
|
-
# @return [Boolean]
|
19
|
-
|
20
|
-
#
|
21
|
-
# Invert the type
|
22
|
-
#
|
23
|
-
# @return [UpDownType] +UP+ if +DOWN+, +DOWN+ if +UP+
|
24
|
-
#
|
25
|
-
def !
|
26
|
-
return UP if down?
|
27
|
-
return DOWN if up?
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/openhab/dsl/units.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
|
5
|
-
# Import Imperial and SI Units overriding provided values
|
6
|
-
%i[Units ImperialUnits SIUnits].each do |type|
|
7
|
-
Object.send(:remove_const, type)
|
8
|
-
java_import "org.openhab.core.library.unit.#{type}"
|
9
|
-
end
|
10
|
-
|
11
|
-
Object.send(:remove_const, :QuantityType)
|
12
|
-
java_import org.openhab.core.library.types.QuantityType
|
13
|
-
|
14
|
-
module OpenHAB
|
15
|
-
module DSL
|
16
|
-
#
|
17
|
-
# Provides support for interacting with OpenHAB Units of Measurement
|
18
|
-
#
|
19
|
-
module Units
|
20
|
-
module_function
|
21
|
-
|
22
|
-
# @return The default unit for the current thread
|
23
|
-
def unit(unit = nil, &block)
|
24
|
-
return with_unit(unit, &block) if unit || block # back-compat
|
25
|
-
|
26
|
-
Thread.current[:unit]
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# Sets a thread local variable to the supplied unit such that classes operating inside the block
|
31
|
-
# can perform automatic conversions to the supplied unit for NumberItems
|
32
|
-
#
|
33
|
-
# @param [Object] unit OpenHAB Unit or String representing unit
|
34
|
-
# @yield [] Block executed in context of the supplied unit
|
35
|
-
#
|
36
|
-
def with_unit(unit)
|
37
|
-
unit = org.openhab.core.types.util.UnitUtils.parse_unit(unit) if unit.is_a? String
|
38
|
-
Thread.current[:unit] = unit
|
39
|
-
yield
|
40
|
-
ensure
|
41
|
-
Thread.current[:unit] = nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
# Supports Logging
|
5
|
-
module Log
|
6
|
-
# This module holds global configuration values
|
7
|
-
module Configuration
|
8
|
-
# -*- coding: utf-8 -*-
|
9
|
-
LOG_PREFIX = 'org.openhab.automation.jruby'
|
10
|
-
|
11
|
-
#
|
12
|
-
# Gets the log prefix
|
13
|
-
#
|
14
|
-
# @return [String] Prefix for all log entries
|
15
|
-
#
|
16
|
-
def self.log_prefix
|
17
|
-
LOG_PREFIX
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/openhab/log/logger.rb
DELETED
@@ -1,282 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openhab/log/configuration'
|
4
|
-
require 'java'
|
5
|
-
|
6
|
-
module OpenHAB
|
7
|
-
module Core
|
8
|
-
#
|
9
|
-
# Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
|
10
|
-
#
|
11
|
-
class Logger
|
12
|
-
java_import org.slf4j.LoggerFactory
|
13
|
-
|
14
|
-
# @return [Array] Supported logging levels
|
15
|
-
LEVELS = %i[trace debug warn info error].freeze
|
16
|
-
private_constant :LEVELS
|
17
|
-
|
18
|
-
#
|
19
|
-
# Regex for matching internal calls in a stack trace
|
20
|
-
#
|
21
|
-
INTERNAL_CALL_REGEX = %r{(openhab-scripting-.*/lib)|org[./]jruby}.freeze
|
22
|
-
private_constant :INTERNAL_CALL_REGEX
|
23
|
-
|
24
|
-
#
|
25
|
-
# Regex for matching internal calls in a java stack trace
|
26
|
-
#
|
27
|
-
EXCLUDED_JAVA_PACKAGES = /jdk\.internal\.reflect|java\.lang\.reflect|org\.openhab|java\.lang\.Thread\.run/.freeze
|
28
|
-
private_constant :EXCLUDED_JAVA_PACKAGES
|
29
|
-
|
30
|
-
#
|
31
|
-
# Regex for matching internal calls in a java stack trace
|
32
|
-
#
|
33
|
-
JAVA_INTERNAL_CALL_REGEX = Regexp.union(INTERNAL_CALL_REGEX, EXCLUDED_JAVA_PACKAGES).freeze
|
34
|
-
private_constant :JAVA_INTERNAL_CALL_REGEX
|
35
|
-
|
36
|
-
#
|
37
|
-
# Create a new logger
|
38
|
-
#
|
39
|
-
# @param [String] name of the logger
|
40
|
-
#
|
41
|
-
def initialize(name)
|
42
|
-
@sl4fj_logger = LoggerFactory.getLogger(name)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Dynamically define the methods for each level as identified by the levels constant
|
46
|
-
# This creates a method for each level that looks like this
|
47
|
-
# def <level>(msg=nil, &block)
|
48
|
-
# log(severity: <level>, msg: msg, &block)
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# Also creates methods to check if the different logging levels are enabled
|
52
|
-
#
|
53
|
-
LEVELS.each do |level|
|
54
|
-
define_method(level) do |msg = nil, &block|
|
55
|
-
log(severity: level, msg: msg, &block)
|
56
|
-
end
|
57
|
-
define_method("#{level}?") { @sl4fj_logger.send("is_#{level}_enabled") }
|
58
|
-
# @deprecated
|
59
|
-
alias_method "#{level}_enabled?", "#{level}?"
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Logs a map of key(value) with an optional preamble at trace level
|
64
|
-
# @param [String] preamble to put at start of log message
|
65
|
-
# @param [Hash] kwargs key and values to log
|
66
|
-
def state(preamble = 'State:', **kwargs)
|
67
|
-
return unless trace?
|
68
|
-
|
69
|
-
states = kwargs.transform_keys(&:to_s)
|
70
|
-
.transform_keys(&:capitalize)
|
71
|
-
.transform_values { |v| v.nil? ? 'nil' : v }
|
72
|
-
.map { |k, v| "#{k}(#{v})" }
|
73
|
-
.join(' ')
|
74
|
-
trace "#{preamble} #{states}"
|
75
|
-
end
|
76
|
-
alias states state
|
77
|
-
|
78
|
-
#
|
79
|
-
# Cleans the backtrace of an error to remove internal calls. If logging is set
|
80
|
-
# to debug or lower, the full backtrace is kept
|
81
|
-
#
|
82
|
-
# @param [Exception] error An exception to be cleaned
|
83
|
-
#
|
84
|
-
# @return [Exception] the exception, potentially with a cleaned backtrace.
|
85
|
-
#
|
86
|
-
def clean_backtrace(error)
|
87
|
-
return error if debug?
|
88
|
-
|
89
|
-
if error.respond_to? :backtrace_locations
|
90
|
-
backtrace = error.backtrace_locations.map(&:to_s).grep_v(INTERNAL_CALL_REGEX)
|
91
|
-
error.set_backtrace(backtrace)
|
92
|
-
elsif error.respond_to? :stack_trace
|
93
|
-
backtrace = error.stack_trace.reject { |line| JAVA_INTERNAL_CALL_REGEX.match? line.to_s }
|
94
|
-
error.set_stack_trace(backtrace)
|
95
|
-
end
|
96
|
-
error
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# Print error and stack trace without calls to internal classes
|
101
|
-
#
|
102
|
-
# @param [Exception] exception A rescued error
|
103
|
-
# @param [String] rule_name The name of the rule where the exception occurred
|
104
|
-
#
|
105
|
-
def log_exception(exception, rule_name)
|
106
|
-
exception = clean_backtrace(exception)
|
107
|
-
error do
|
108
|
-
"#{exception.message} (#{exception.class})\nIn rule: #{rule_name}\n#{exception.backtrace&.join("\n")}"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
#
|
115
|
-
# Log a message to the OpenHAB Logger
|
116
|
-
#
|
117
|
-
# @param [Symbol] severity Severity to log message at
|
118
|
-
# @param [Object] msg to log, if no msg supplied and a block is provided,
|
119
|
-
# the msg is taken from the result of the block
|
120
|
-
#
|
121
|
-
def log(severity:, msg: nil)
|
122
|
-
severity = severity.to_sym
|
123
|
-
|
124
|
-
raise ArgumentError, "Unknown Severity #{severity}" unless LEVELS.include? severity
|
125
|
-
|
126
|
-
# Dynamically check enablement of underlying logger, this expands to "is_<level>_enabled"
|
127
|
-
return unless send("#{severity}?")
|
128
|
-
|
129
|
-
# Process block if no message provided
|
130
|
-
msg = yield if msg.nil? && block_given?
|
131
|
-
|
132
|
-
msg = message_to_string(msg: msg)
|
133
|
-
|
134
|
-
# Dynamically invoke underlying logger, this expands to "<level>(message)"
|
135
|
-
@sl4fj_logger.send(severity, msg)
|
136
|
-
end
|
137
|
-
|
138
|
-
#
|
139
|
-
# Conver the supplied message object to a String
|
140
|
-
#
|
141
|
-
# @param [object] msg object to convert
|
142
|
-
#
|
143
|
-
# @return [String] Msg object as a string
|
144
|
-
#
|
145
|
-
def message_to_string(msg:)
|
146
|
-
case msg
|
147
|
-
when ::String
|
148
|
-
msg
|
149
|
-
when ::Exception
|
150
|
-
"#{msg.message} (#{msg.class})\n#{msg.backtrace&.join("\n")}"
|
151
|
-
else
|
152
|
-
msg.inspect
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
#
|
159
|
-
# Provides access to the OpenHAB logging using a Ruby logging methods
|
160
|
-
#
|
161
|
-
module Log
|
162
|
-
module_function
|
163
|
-
|
164
|
-
# Logger caches
|
165
|
-
@loggers = {}
|
166
|
-
|
167
|
-
# Return a logger with the configured log prefix plus the calling scripts name
|
168
|
-
|
169
|
-
#
|
170
|
-
# Create a logger for the current class
|
171
|
-
#
|
172
|
-
# @return [Logger] for the current class
|
173
|
-
#
|
174
|
-
def logger
|
175
|
-
Log.logger(self)
|
176
|
-
end
|
177
|
-
|
178
|
-
class << self
|
179
|
-
#
|
180
|
-
# Injects a logger into the base class
|
181
|
-
#
|
182
|
-
# @param [Object] object the logger is for
|
183
|
-
#
|
184
|
-
# @return [Logger] for the supplied name
|
185
|
-
#
|
186
|
-
def logger(object)
|
187
|
-
# Cache logger instances for each object since construction
|
188
|
-
# of logger name requires lots of operations and logger
|
189
|
-
# names for some objects are specific to the class
|
190
|
-
logger_name = logger_name(object)
|
191
|
-
@loggers[logger_name] ||= Core::Logger.new(logger_name)
|
192
|
-
end
|
193
|
-
|
194
|
-
private
|
195
|
-
|
196
|
-
# Construct the logger name from the supplied object
|
197
|
-
# @param [Object] object to construct logger name from
|
198
|
-
# @return name for logger based on object
|
199
|
-
def logger_name(object)
|
200
|
-
name = Configuration.log_prefix
|
201
|
-
name += rules_file || ''
|
202
|
-
name += rule_name || ''
|
203
|
-
name += klass_name(object) || ''
|
204
|
-
name.tr_s(' ', '_').gsub('::', '.')
|
205
|
-
end
|
206
|
-
|
207
|
-
# Get the class name for the supplied object
|
208
|
-
# @param [Object] object to derive class name for
|
209
|
-
# @return [String] name of class for logging
|
210
|
-
def klass_name(object)
|
211
|
-
object = object.class unless object.is_a?(Class)
|
212
|
-
object.then { |klass| java_klass(klass) }
|
213
|
-
.then(&:name)
|
214
|
-
.then { |name| filter_base_classes(name) }
|
215
|
-
.then { |name| ".#{name}" unless name.nil? } # name is frozen in jruby 9.4
|
216
|
-
end
|
217
|
-
|
218
|
-
# Get the appropriate java class for the supplied klass if the supplied
|
219
|
-
# class is a java class
|
220
|
-
# @param [Class] klass to inspect
|
221
|
-
# @return Class or Java class of supplied class
|
222
|
-
def java_klass(klass)
|
223
|
-
if klass.respond_to?(:java_class) &&
|
224
|
-
klass.java_class &&
|
225
|
-
!klass.java_class.name.start_with?('org.jruby.Ruby') &&
|
226
|
-
!klass.java_class.name.start_with?('org.jruby.gen')
|
227
|
-
klass = klass.java_class
|
228
|
-
end
|
229
|
-
klass
|
230
|
-
end
|
231
|
-
|
232
|
-
#
|
233
|
-
# Returns the rules file name
|
234
|
-
#
|
235
|
-
def rules_file
|
236
|
-
# Each rules file gets its own context
|
237
|
-
# Set it once as a class value so that threads not
|
238
|
-
# tied to a rules file pick up the rules file they
|
239
|
-
# were spawned from
|
240
|
-
@rules_file ||= log_caller&.downcase&.prepend('.')
|
241
|
-
end
|
242
|
-
|
243
|
-
# Get the name of the rule from the thread context
|
244
|
-
def rule_name
|
245
|
-
Thread.current[:RULE_NAME]&.downcase&.prepend('.')
|
246
|
-
end
|
247
|
-
|
248
|
-
# Filter out the base classes of Object and Module from the log name
|
249
|
-
def filter_base_classes(klass_name)
|
250
|
-
return nil if %w[Object Module].include?(klass_name)
|
251
|
-
|
252
|
-
klass_name
|
253
|
-
end
|
254
|
-
|
255
|
-
#
|
256
|
-
# Figure out the log prefix
|
257
|
-
#
|
258
|
-
# @return [String] Prefix for log messages
|
259
|
-
#
|
260
|
-
def log_caller
|
261
|
-
caller_locations.map(&:path)
|
262
|
-
.grep_v(/rubygems|openhab-scripting|<script>/)
|
263
|
-
.first
|
264
|
-
.then { |caller| File.basename(caller, '.*') if caller }
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
#
|
269
|
-
# Add logger method to the object that includes this module
|
270
|
-
#
|
271
|
-
# @param [Object] base Object to add method to
|
272
|
-
#
|
273
|
-
#
|
274
|
-
def self.included(base)
|
275
|
-
class << base
|
276
|
-
def logger
|
277
|
-
Log.logger(self)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
data/lib/openhab/version.rb
DELETED
data/lib/openhab.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
require 'openhab/core/load_path'
|
5
|
-
require 'openhab/core/entity_lookup'
|
6
|
-
require 'openhab/core/script_handling'
|
7
|
-
require 'openhab/core/openhab_setup'
|
8
|
-
require 'openhab/log/logger'
|
9
|
-
require 'openhab/dsl/dsl'
|
10
|
-
require 'openhab/version'
|
11
|
-
|
12
|
-
#
|
13
|
-
# Module used to extend base object with OpenHAB Library functionality
|
14
|
-
#
|
15
|
-
module OpenHAB
|
16
|
-
include OpenHAB::Log
|
17
|
-
#
|
18
|
-
# Extends calling object with DSL and helper methods
|
19
|
-
#
|
20
|
-
# @param [Object] base Object to decorate with DSL and helper methods
|
21
|
-
#
|
22
|
-
def self.extended(base)
|
23
|
-
OpenHAB::Core.wait_till_openhab_ready
|
24
|
-
base.extend OpenHAB::Core::ScriptHandling
|
25
|
-
base.extend OpenHAB::Core::ScriptHandlingCallbacks
|
26
|
-
base.extend OpenHAB::Core::EntityLookup
|
27
|
-
base.extend OpenHAB::DSL
|
28
|
-
|
29
|
-
logger.debug "OpenHAB JRuby (Version #{JRUBY_VERSION}) Scripting Library (Version #{OpenHAB::VERSION}) " \
|
30
|
-
"Supporting Ruby (Version #{RUBY_VERSION})"
|
31
|
-
logger.trace "Ruby Description (#{RUBY_DESCRIPTION})"
|
32
|
-
|
33
|
-
OpenHAB::Core.add_rubylib_to_load_path
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Extend caller with OpenHAB methods
|
38
|
-
extend OpenHAB # rubocop:disable Style/MixinUsage
|