openhab-scripting 2.16.2 → 2.16.3

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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab.rb +12 -16
  3. data/lib/openhab/core/entity_lookup.rb +162 -0
  4. data/lib/openhab/core/openhab_setup.rb +31 -0
  5. data/lib/openhab/core/osgi.rb +61 -0
  6. data/lib/openhab/dsl/actions.rb +105 -0
  7. data/lib/openhab/dsl/dsl.rb +47 -0
  8. data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
  9. data/lib/openhab/dsl/group.rb +100 -0
  10. data/lib/openhab/dsl/items/items.rb +46 -0
  11. data/lib/openhab/dsl/items/number_item.rb +352 -0
  12. data/lib/openhab/dsl/items/string_item.rb +120 -0
  13. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
  14. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
  15. data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
  16. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
  17. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
  18. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
  19. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
  20. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
  21. data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
  22. data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
  23. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
  24. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
  25. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
  26. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
  27. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
  28. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +7 -0
  29. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
  30. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
  31. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
  32. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
  33. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
  34. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
  35. data/lib/openhab/dsl/monkey_patch/types/types.rb +8 -0
  36. data/lib/openhab/dsl/persistence.rb +25 -0
  37. data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
  38. data/lib/openhab/dsl/rules/guard.rb +134 -0
  39. data/lib/openhab/dsl/rules/property.rb +102 -0
  40. data/lib/openhab/dsl/rules/rule.rb +116 -0
  41. data/lib/openhab/dsl/rules/rule_config.rb +151 -0
  42. data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
  43. data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
  44. data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
  45. data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
  46. data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
  47. data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
  48. data/lib/openhab/dsl/states.rb +61 -0
  49. data/lib/openhab/dsl/things.rb +91 -0
  50. data/lib/openhab/dsl/time_of_day.rb +228 -0
  51. data/lib/openhab/dsl/timers.rb +77 -0
  52. data/lib/openhab/dsl/types/quantity.rb +290 -0
  53. data/lib/openhab/dsl/units.rb +39 -0
  54. data/lib/openhab/log/configuration.rb +21 -0
  55. data/lib/openhab/log/logger.rb +172 -0
  56. data/lib/openhab/version.rb +1 -1
  57. metadata +55 -58
  58. data/lib/openhab/configuration.rb +0 -16
  59. data/lib/openhab/core/cron.rb +0 -27
  60. data/lib/openhab/core/debug.rb +0 -34
  61. data/lib/openhab/core/dsl.rb +0 -51
  62. data/lib/openhab/core/dsl/actions.rb +0 -107
  63. data/lib/openhab/core/dsl/entities.rb +0 -147
  64. data/lib/openhab/core/dsl/group.rb +0 -102
  65. data/lib/openhab/core/dsl/items/items.rb +0 -51
  66. data/lib/openhab/core/dsl/items/number_item.rb +0 -323
  67. data/lib/openhab/core/dsl/items/string_item.rb +0 -122
  68. data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
  69. data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
  70. data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
  71. data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
  72. data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
  73. data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
  74. data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
  75. data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
  76. data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
  77. data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
  78. data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
  79. data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
  80. data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
  81. data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
  82. data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
  83. data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
  84. data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
  85. data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
  86. data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
  87. data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
  88. data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
  89. data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
  90. data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
  91. data/lib/openhab/core/dsl/persistence.rb +0 -27
  92. data/lib/openhab/core/dsl/property.rb +0 -96
  93. data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
  94. data/lib/openhab/core/dsl/rule/guard.rb +0 -136
  95. data/lib/openhab/core/dsl/rule/rule.rb +0 -117
  96. data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
  97. data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
  98. data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
  99. data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
  100. data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
  101. data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
  102. data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
  103. data/lib/openhab/core/dsl/states.rb +0 -63
  104. data/lib/openhab/core/dsl/things.rb +0 -93
  105. data/lib/openhab/core/dsl/time_of_day.rb +0 -231
  106. data/lib/openhab/core/dsl/timers.rb +0 -79
  107. data/lib/openhab/core/dsl/types/quantity.rb +0 -292
  108. data/lib/openhab/core/dsl/units.rb +0 -41
  109. data/lib/openhab/core/log.rb +0 -170
  110. data/lib/openhab/core/patch_load_path.rb +0 -7
  111. data/lib/openhab/core/startup_delay.rb +0 -23
  112. data/lib/openhab/osgi.rb +0 -59
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- java_import org.openhab.core.library.items.SwitchItem
4
-
5
- # Alias class names for easy is_a? comparisons
6
- Switch = SwitchItem
7
-
8
- #
9
- # Monkeypatching SwitchItem to add Ruby Support methods
10
- #
11
- # rubocop:disable Style/ClassAndModuleChildren
12
- class Java::OrgOpenhabCoreLibraryItems::SwitchItem
13
- java_import org.openhab.core.library.types.OnOffType
14
- # rubocop:enable Style/ClassAndModuleChildren
15
-
16
- #
17
- # Send the OFF command to the switch
18
- #
19
- #
20
- def off
21
- command(OnOffType::OFF)
22
- end
23
-
24
- #
25
- # Send the OFF command to the switch
26
- #
27
- #
28
- def on
29
- command(OnOffType::ON)
30
- end
31
-
32
- #
33
- # Check if a switch is on
34
- #
35
- # @return [Boolean] True if the switch is on, false otherwise
36
- #
37
- def on?
38
- state? && state == OnOffType::ON
39
- end
40
-
41
- alias truthy? on?
42
-
43
- #
44
- # Check if a switch is off
45
- #
46
- # @return [Boolean] True if the switch is off, false otherwise
47
- #
48
- def off?
49
- state? && state == OnOffType::OFF
50
- end
51
-
52
- #
53
- # Send a command to invert the state of the switch
54
- #
55
- # @return [OnOffType] Inverted state
56
- #
57
- def toggle
58
- self << !self
59
- end
60
-
61
- #
62
- # Return the inverted state of the switch: ON if the switch is OFF, UNDEF or NULL; OFF if the switch is ON
63
- #
64
- # @return [OnOffType] Inverted state
65
- #
66
- def !
67
- return !state if state?
68
-
69
- OnOffType::ON
70
- end
71
-
72
- #
73
- # Check for equality against supplied object
74
- #
75
- # @param [Object] other object to compare to
76
- #
77
- # @return [Boolean] True if other is a OnOffType and other equals state for this switch item,
78
- # otherwise result from super
79
- #
80
- def ==(other)
81
- if other.is_a? OnOffType
82
- state? && state == other
83
- else
84
- super
85
- end
86
- end
87
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module Core
5
- module DSL
6
- module MonkeyPatch
7
- module Ruby
8
- #
9
- # Extend integer to create duration object
10
- #
11
- module IntegerExtensions
12
- include OpenHAB::Core
13
-
14
- #
15
- # Create Duration with the specified unit
16
- #
17
- # @return [Java::JavaTime::Duration] Duration with number of units from self
18
- #
19
- %w[millis seconds minutes hours].each do |unit|
20
- define_method(unit) { Java::JavaTime::Duration.public_send("of_#{unit}", self) }
21
- end
22
-
23
- alias second seconds
24
- alias millisecond millis
25
- alias milliseconds millis
26
- alias ms millis
27
- alias minute minutes
28
- alias hour hours
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
-
36
- #
37
- # Prepend Integer class with duration extensions
38
- #
39
- class Integer
40
- prepend OpenHAB::Core::DSL::MonkeyPatch::Ruby::IntegerExtensions
41
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- # Monkey patch range to support case equality of OpenHab "Numeric" Objects
6
-
7
- module OpenHAB
8
- module Core
9
- module DSL
10
- #
11
- # MonkeyPatch both Ruby and OpenHAB Objects to support DSL
12
- #
13
- module MonkeyPatch
14
- #
15
- # MonkeyPatch ruby object to support DSL
16
- #
17
- module Ruby
18
- #
19
- # Extensions for Range Class to support DimmerItems
20
- #
21
- module RangeExtensions
22
- #
23
- # Override range === method to support DimmerItems
24
- #
25
- # @param [Object] other object to compare for case equals
26
- #
27
- # @return [Boolean] if other is DimmerItem and state is covered by range,
28
- # result from parent Range class if not DimmerItem
29
- #
30
- def ===(other)
31
- return super unless other.is_a? DimmerItem
32
-
33
- cover? other.state.to_i
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
-
42
- #
43
- # Prepend Range class with RangeExtensions
44
- #
45
- class Range
46
- prepend OpenHAB::Core::DSL::MonkeyPatch::Ruby::RangeExtensions
47
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Monkey patch ruby
4
- require 'openhab/core/dsl/monkey_patch/ruby/range'
5
- require 'openhab/core/dsl/monkey_patch/ruby/number'
6
- require 'openhab/core/dsl/monkey_patch/ruby/string'
7
- require 'bigdecimal/util'
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openhab/core/dsl/types/quantity'
4
-
5
- module OpenHAB
6
- module Core
7
- module DSL
8
- module MonkeyPatch
9
- module Ruby
10
- #
11
- # Extend String class
12
- #
13
- module StringExtensions
14
- include OpenHAB::Core
15
-
16
- #
17
- # Compares String to another object
18
- #
19
- # @param [Object] other object to compare to
20
- #
21
- # @return [Boolean] true if the two objects contain the same value, false otherwise
22
- #
23
- def ==(other)
24
- case other
25
- when OpenHAB::Core::DSL::Types::Quantity, QuantityType
26
- other == self
27
- else
28
- super
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- #
39
- # Prepend String class with comparison extensions
40
- #
41
- class String
42
- prepend OpenHAB::Core::DSL::MonkeyPatch::Ruby::StringExtensions
43
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- #
6
- # MonkeyPatching Decimal Type
7
- #
8
- # rubocop:disable Style/ClassAndModuleChildren
9
- class Java::OrgOpenhabCoreLibraryTypes::DecimalType
10
- # rubocop:enable Style/ClassAndModuleChildren
11
-
12
- #
13
- # Compare DecimalType to supplied object
14
- #
15
- # @param [Object] other object to compare to
16
- #
17
- # @return [Integer] -1,0,1 or nil depending on value supplied, nil comparison to supplied object is not possible.
18
- #
19
- def <=>(other)
20
- logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
21
- case other
22
- when Numeric
23
- to_big_decimal.compare_to(other.to_d)
24
- when Java::OrgOpenhabCoreTypes::UnDefType
25
- 1
26
- else
27
- other = other.state if other.respond_to? :state
28
- compare_to(other)
29
- end
30
- end
31
-
32
- #
33
- # Coerce objects into a DecimalType
34
- #
35
- # @param [Object] other object to coerce to a DecimalType if possible
36
- #
37
- # @return [Object] Numeric when applicable
38
- #
39
- def coerce(other)
40
- logger.trace("Coercing #{self} as a request from #{other.class}")
41
- case other
42
- when Numeric
43
- [other.to_d, to_big_decimal]
44
- else
45
- [other, self]
46
- end
47
- end
48
-
49
- #
50
- # Compare self to other through the spaceship operator
51
- #
52
- # @param [Object] other object to compare to
53
- #
54
- # @return [Boolean] True if equals
55
- #
56
- def ==(other)
57
- logger.trace("#{self.class} #{self} == #{other} (#{other.class})")
58
- (self <=> other).zero?
59
- end
60
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- #
6
- # Monkey patching OnOffType
7
- #
8
- # rubocop:disable Style/ClassAndModuleChildren
9
- class Java::OrgOpenhabCoreLibraryTypes::OnOffType
10
- # rubocop:enable Style/ClassAndModuleChildren
11
-
12
- #
13
- # Invert the type
14
- #
15
- # @return [Java::OrgOpenhabCoreLibraryTypes::OnOffType] OFF if ON, ON if OFF
16
- #
17
- def !
18
- return OFF if self == ON
19
- return ON if self == OFF
20
- end
21
-
22
- # Check if the supplied object is case equals to self
23
- #
24
- # @param [Object] other object to compare
25
- #
26
- # @return [Boolean] True if the other object responds to on?/off? and is in the same state as this object,
27
- # nil if object cannot be compared
28
- #
29
- def ===(other)
30
- # A case statement here causes and infinite loop
31
- # rubocop:disable Style/CaseLikeIf
32
- if self == ON
33
- other.on? if other.respond_to? :on?
34
- elsif self == OFF
35
- other.off? if other.respond_to?('off?')
36
- else
37
- false
38
- end
39
- # rubocop:enable Style/CaseLikeIf
40
- end
41
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- #
6
- # Monkey patch for DSL use
7
- #
8
- # rubocop:disable Style/ClassAndModuleChildren
9
- class Java::OrgOpenhabCoreLibraryTypes::OpenClosedType
10
- # rubocop:enable Style/ClassAndModuleChildren
11
- java_import org.openhab.core.library.items.ContactItem
12
-
13
- #
14
- # Check if the supplied object is case equals to self
15
- #
16
- # @param [Object] other object to compare
17
- #
18
- # @return [Boolean] True if the other object is a ContactItem and has the same state
19
- #
20
- def ===(other)
21
- super unless other.is_a? ContactItem
22
-
23
- self == other.state
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- #
6
- # MonkeyPatching PercentType
7
- #
8
- # rubocop:disable Style/ClassAndModuleChildren
9
- class Java::OrgOpenhabCoreLibraryTypes::PercentType
10
- # rubocop:enable Style/ClassAndModuleChildren
11
-
12
- #
13
- # Need to override and point to super because default JRuby implementation doesn't point to == of parent class
14
- #
15
- # @param [Object] other object to check equality for
16
- # @return [Boolean] True if other equals self, false otherwise
17
- #
18
- # rubocop:disable Lint/UselessMethodDefinition
19
- def ==(other)
20
- super
21
- end
22
- # rubocop:enable Lint/UselessMethodDefinition
23
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- #
6
- # MonkeyPatching QuantityType
7
- #
8
- # rubocop:disable Style/ClassAndModuleChildren
9
- class Java::OrgOpenhabCoreLibraryTypes::QuantityType
10
- # rubocop:enable Style/ClassAndModuleChildren
11
-
12
- #
13
- # Compare QuantityType to supplied object
14
- #
15
- # @param [Object] other object to compare to
16
- #
17
- # @return [Integer] -1,0,1 or nil depending on value supplied, nil comparison to supplied object is not possible.
18
- #
19
- def <=>(other)
20
- logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
21
- case other
22
- when Java::OrgOpenhabCoreTypes::UnDefType then 1
23
- when String then self <=> Quantity.new(other)
24
- when OpenHAB::Core::DSL::Types::Quantity then self <=> other.quantity
25
- else
26
- other = other.state if other.respond_to? :state
27
- compare_to(other)
28
- end
29
- end
30
-
31
- #
32
- # Coerce objects into a QuantityType
33
- #
34
- # @param [Object] other object to coerce to a QuantityType if possible
35
- #
36
- # @return [Object] Numeric when applicable
37
- #
38
- def coerce(other)
39
- logger.trace("Coercing #{self} as a request from #{other.class}")
40
- case other
41
- when String
42
- [Quantity.new(other), self]
43
- else
44
- [other, self]
45
- end
46
- end
47
-
48
- #
49
- # Compare self to other using the spaceship operator
50
- #
51
- # @param [Object] other object to compare to
52
- #
53
- # @return [Boolean] True if equals
54
- #
55
- def ==(other)
56
- (self <=> other).zero?
57
- end
58
- end