openhab-scripting 4.1.4 → 4.5.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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/entity_lookup.rb +1 -57
  3. data/lib/openhab/dsl/actions.rb +2 -3
  4. data/lib/openhab/dsl/dsl.rb +8 -12
  5. data/lib/openhab/dsl/group.rb +1 -5
  6. data/lib/openhab/dsl/items/color_item.rb +60 -0
  7. data/lib/openhab/dsl/items/comparable_item.rb +49 -0
  8. data/lib/openhab/dsl/items/contact_item.rb +41 -0
  9. data/lib/openhab/dsl/items/date_time_item.rb +64 -0
  10. data/lib/openhab/dsl/items/dimmer_item.rb +59 -0
  11. data/lib/openhab/dsl/items/ensure.rb +93 -0
  12. data/lib/openhab/dsl/items/generic_item.rb +174 -0
  13. data/lib/openhab/dsl/items/group_item.rb +121 -89
  14. data/lib/openhab/dsl/items/image_item.rb +5 -41
  15. data/lib/openhab/dsl/items/item_equality.rb +36 -0
  16. data/lib/openhab/dsl/items/item_registry.rb +49 -0
  17. data/lib/openhab/dsl/items/items.rb +81 -35
  18. data/lib/openhab/dsl/items/metadata.rb +325 -0
  19. data/lib/openhab/dsl/items/number_item.rb +6 -312
  20. data/lib/openhab/dsl/items/numeric_item.rb +68 -0
  21. data/lib/openhab/dsl/items/persistence.rb +122 -0
  22. data/lib/openhab/dsl/items/player_item.rb +49 -40
  23. data/lib/openhab/dsl/items/rollershutter_item.rb +25 -77
  24. data/lib/openhab/dsl/items/string_item.rb +16 -58
  25. data/lib/openhab/dsl/items/switch_item.rb +62 -0
  26. data/lib/openhab/dsl/lazy_array.rb +8 -6
  27. data/lib/openhab/dsl/monkey_patch/events/events.rb +2 -2
  28. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +67 -24
  29. data/lib/openhab/dsl/monkey_patch/events/item_event.rb +5 -5
  30. data/lib/openhab/dsl/monkey_patch/events/item_state.rb +10 -11
  31. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +10 -11
  32. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +25 -2
  33. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -3
  34. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +24 -24
  35. data/lib/openhab/dsl/rules/terse.rb +24 -0
  36. data/lib/openhab/dsl/states.rb +1 -1
  37. data/lib/openhab/dsl/time_of_day.rb +3 -5
  38. data/lib/openhab/dsl/types/comparable_type.rb +21 -0
  39. data/lib/openhab/dsl/types/date_time_type.rb +334 -0
  40. data/lib/openhab/dsl/types/decimal_type.rb +187 -0
  41. data/lib/openhab/dsl/types/hsb_type.rb +201 -0
  42. data/lib/openhab/dsl/types/increase_decrease_type.rb +23 -0
  43. data/lib/openhab/dsl/types/next_previous_type.rb +23 -0
  44. data/lib/openhab/dsl/types/numeric_type.rb +39 -0
  45. data/lib/openhab/dsl/types/on_off_type.rb +29 -0
  46. data/lib/openhab/dsl/types/open_closed_type.rb +29 -0
  47. data/lib/openhab/dsl/types/percent_type.rb +70 -0
  48. data/lib/openhab/dsl/types/play_pause_type.rb +27 -0
  49. data/lib/openhab/dsl/types/quantity_type.rb +275 -0
  50. data/lib/openhab/dsl/types/refresh_type.rb +18 -0
  51. data/lib/openhab/dsl/types/rewind_fastforward_type.rb +33 -0
  52. data/lib/openhab/dsl/types/stop_move_type.rb +23 -0
  53. data/lib/openhab/dsl/types/string_type.rb +88 -0
  54. data/lib/openhab/dsl/types/type.rb +72 -0
  55. data/lib/openhab/dsl/types/types.rb +78 -0
  56. data/lib/openhab/dsl/types/un_def_type.rb +22 -0
  57. data/lib/openhab/dsl/types/up_down_type.rb +32 -0
  58. data/lib/openhab/dsl/units.rb +11 -6
  59. data/lib/openhab/version.rb +1 -1
  60. data/lib/openhab.rb +0 -1
  61. metadata +36 -28
  62. data/lib/openhab/dsl/items/datetime_item.rb +0 -75
  63. data/lib/openhab/dsl/items/item_command.rb +0 -90
  64. data/lib/openhab/dsl/items/item_delegate.rb +0 -125
  65. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +0 -51
  66. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +0 -140
  67. data/lib/openhab/dsl/monkey_patch/items/items.rb +0 -142
  68. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +0 -328
  69. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +0 -123
  70. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +0 -71
  71. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +0 -47
  72. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -32
  73. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +0 -97
  74. data/lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb +0 -23
  75. data/lib/openhab/dsl/monkey_patch/types/next_previous_type.rb +0 -23
  76. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +0 -79
  77. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +0 -71
  78. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +0 -77
  79. data/lib/openhab/dsl/monkey_patch/types/play_pause_type.rb +0 -23
  80. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +0 -69
  81. data/lib/openhab/dsl/monkey_patch/types/refresh_type.rb +0 -23
  82. data/lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb +0 -23
  83. data/lib/openhab/dsl/monkey_patch/types/stop_move_type.rb +0 -23
  84. data/lib/openhab/dsl/monkey_patch/types/types.rb +0 -15
  85. data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +0 -72
  86. data/lib/openhab/dsl/types/datetime.rb +0 -338
  87. data/lib/openhab/dsl/types/quantity.rb +0 -300
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module MonkeyPatch
6
- module Ruby
7
- #
8
- # Extend Time to make to_s return string parseable by OpenHAB
9
- #
10
- module TimeExtensions
11
- include OpenHAB::Core
12
-
13
- #
14
- # Convert to ISO 8601 format
15
- #
16
- # @return [Java::JavaTime::Duration] Duration with number of units from self
17
- #
18
- def to_s
19
- strftime '%FT%T.%N%:z'
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
-
27
- #
28
- # Extend Time class with to_s method
29
- #
30
- class Time
31
- prepend OpenHAB::DSL::MonkeyPatch::Ruby::TimeExtensions
32
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::DecimalType
13
- java_import org.openhab.core.types.util.UnitUtils
14
-
15
- #
16
- # MonkeyPatching Decimal Type
17
- #
18
- class DecimalType
19
- extend Forwardable
20
-
21
- delegate %i[to_d zero?] => :to_big_decimal
22
- delegate %i[positive? negative?] => :to_d
23
-
24
- #
25
- # @param [Object] other object to compare to
26
- #
27
- # @return [Integer] -1,0,1 or nil depending on value supplied,
28
- # nil comparison to supplied object is not possible.
29
- #
30
- def <=>(other)
31
- logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
32
- case other
33
- when Numeric
34
- to_big_decimal.compare_to(other.to_d)
35
- when Java::OrgOpenhabCoreTypes::UnDefType
36
- 1
37
- else
38
- other = other.state if other.respond_to? :state
39
- compare_to(other)
40
- end
41
- end
42
-
43
- #
44
- # Coerce objects into a DecimalType
45
- #
46
- # @param [Object] other object to coerce to a DecimalType if possible
47
- #
48
- # @return [Object] Numeric when applicable
49
- #
50
- def coerce(other)
51
- logger.trace("Coercing #{self} as a request from #{other.class}")
52
- case other
53
- when Numeric
54
- [other.to_d, to_big_decimal]
55
- else
56
- [other, self]
57
- end
58
- end
59
-
60
- #
61
- # Compare self to other through the spaceship operator
62
- # Compare self to other using Java BigDecimal compare method
63
- #
64
- # @param [Object] other object to compare to
65
- #
66
- # @return [Boolean] True if have the same BigDecimal representation, false otherwise
67
- #
68
- def ==(other)
69
- logger.trace("#{self.class} #{self} == #{other} (#{other.class})")
70
- (self <=> other).zero?
71
- end
72
-
73
- #
74
- # Convert DecimalType to a Quantity
75
- #
76
- # @param [Object] other String or Unit representing an OpenHAB Unit
77
- #
78
- # @return [OpenHAB::Core::DSL::Types::Quantity] NumberItem converted to supplied Unit
79
- #
80
- def |(other)
81
- other = UnitUtils.parse_unit(other) if other.is_a? String
82
- Quantity.new(QuantityType.new(to_big_decimal, other))
83
- end
84
-
85
- #
86
- # Provide details about DecimalType object
87
- #
88
- # @return [String] Representing details about the DecimalType object
89
- #
90
- def inspect
91
- to_string
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::IncreaseDecreaseType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class IncreaseDecreaseType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::NextPreviousType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class NextPreviousType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::OnOffType
13
-
14
- #
15
- # Monkey patching OnOffType
16
- #
17
- class OnOffType
18
- #
19
- # Invert the type
20
- #
21
- # @return [Java::OrgOpenhabCoreLibraryTypes::OnOffType] OFF if ON, ON if OFF
22
- #
23
- def !
24
- return OFF if self == ON
25
- return ON if self == OFF
26
- end
27
-
28
- # Check if the supplied object is case equals to self
29
- #
30
- # @param [Object] other object to compare
31
- #
32
- # @return [Boolean] True if the other object responds to on?/off? and is in the same state as this object,
33
- # nil if object cannot be compared
34
- #
35
- def ===(other)
36
- (on? && other.respond_to?(:on?) && other.on?) ||
37
- (off? && other.respond_to?(:off?) && other.off?) ||
38
- super
39
- end
40
-
41
- #
42
- # Test for equality
43
- #
44
- # @param [Object] other Other object to compare against
45
- #
46
- # @return [Boolean] true if self and other can be considered equal, false otherwise
47
- #
48
- def ==(other)
49
- if other.respond_to?(:get_state_as)
50
- self == other.get_state_as(OnOffType)
51
- else
52
- super
53
- end
54
- end
55
-
56
- #
57
- # Check if the state is ON
58
- #
59
- # @return [Boolean] true if ON, false otherwise
60
- #
61
- def on?
62
- self == ON
63
- end
64
-
65
- #
66
- # Check if the state is OFF
67
- #
68
- # @return [Boolean] true if OFF, false otherwise
69
- #
70
- def off?
71
- self == OFF
72
- end
73
-
74
- alias inspect to_s
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::OpenClosedType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class OpenClosedType
18
- java_import Java::OrgOpenhabCoreLibraryItems::ContactItem
19
-
20
- #
21
- # Check if the supplied object is case equals to self
22
- #
23
- # @param [Object] other object to compare
24
- #
25
- # @return [Boolean] True if the other object is a ContactItem and has the same state
26
- #
27
- def ===(other)
28
- (open? && other.respond_to?(:open?) && other.open?) ||
29
- (closed? && other.respond_to?(:closed?) && other.closed?) ||
30
- super
31
- end
32
-
33
- #
34
- # Test for equality
35
- #
36
- # @param [Object] other Other object to compare against
37
- #
38
- # @return [Boolean] true if self and other can be considered equal, false otherwise
39
- #
40
- def ==(other)
41
- if other.respond_to?(:get_state_as)
42
- self == other.get_state_as(OpenClosedType)
43
- else
44
- super
45
- end
46
- end
47
-
48
- #
49
- # Check if the state is OPEN
50
- #
51
- # @return [Boolean] true if OPEN, false otherwise
52
- #
53
- def open?
54
- self == OPEN
55
- end
56
-
57
- #
58
- # Check if the state is CLOSED
59
- #
60
- # @return [Boolean] true if CLOSED, false otherwise
61
- #
62
- def closed?
63
- self == CLOSED
64
- end
65
-
66
- alias inspect to_s
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
- module OpenHAB
5
- module DSL
6
- module MonkeyPatch
7
- #
8
- # Patches OpenHAB types
9
- #
10
- module Types
11
- java_import Java::OrgOpenhabCoreLibraryTypes::PercentType
12
-
13
- #
14
- # MonkeyPatching PercentType
15
- #
16
- class PercentType
17
- #
18
- # Need to override and point to super because default JRuby implementation doesn't point to == of parent class
19
- #
20
- # @param [Object] other object to check equality for
21
- # @return [Boolean] True if other equals self, false otherwise
22
- #
23
- # rubocop:disable Lint/UselessMethodDefinition
24
- def ==(other)
25
- super
26
- end
27
- # rubocop:enable Lint/UselessMethodDefinition
28
-
29
- #
30
- # Provide details about PercentType object
31
- #
32
- # @return [String] Representing details about the PercentType object
33
- #
34
- def inspect
35
- "#{to_string}%"
36
- end
37
-
38
- #
39
- # Check if the state is ON
40
- #
41
- # @return [Boolean] true if ON, false otherwise
42
- #
43
- def on?
44
- as(OnOffType).on?
45
- end
46
-
47
- #
48
- # Check if the state is OFF
49
- #
50
- # @return [Boolean] true if OFF, false otherwise
51
- #
52
- def off?
53
- as(OnOffType).off?
54
- end
55
-
56
- #
57
- # Check if the state is UP
58
- #
59
- # @return [Boolean] true if UP, false otherwise
60
- #
61
- def up?
62
- !!as(UpDownType)&.up?
63
- end
64
-
65
- #
66
- # Check if the state is DOWN
67
- #
68
- # @return [Boolean] true if DOWN, false otherwise
69
- #
70
- def down?
71
- !!as(UpDownType)&.down?
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::PlayPauseType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class PlayPauseType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::QuantityType
13
-
14
- #
15
- # MonkeyPatching QuantityType
16
- #
17
- class QuantityType
18
- #
19
- # Compare QuantityType to supplied object
20
- #
21
- # @param [Object] other object to compare to
22
- #
23
- # @return [Integer] -1,0,1 or nil depending on value supplied,
24
- # nil comparison to supplied object is not possible.
25
- #
26
- def <=>(other)
27
- logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
28
- case other
29
- when Java::OrgOpenhabCoreTypes::UnDefType then 1
30
- when String then self <=> Quantity.new(other)
31
- when OpenHAB::DSL::Types::Quantity then self <=> other.quantity
32
- else
33
- other = other.state if other.respond_to? :state
34
- compare_to(other)
35
- end
36
- end
37
-
38
- #
39
- # Coerce objects into a QuantityType
40
- #
41
- # @param [Object] other object to coerce to a QuantityType if possible
42
- #
43
- # @return [Object] Numeric when applicable
44
- #
45
- def coerce(other)
46
- logger.trace("Coercing #{self} as a request from #{other.class}")
47
- case other
48
- when String
49
- [Quantity.new(other), self]
50
- else
51
- [other, self]
52
- end
53
- end
54
-
55
- #
56
- # Compare self to other using the spaceship operator
57
- #
58
- # @param [Object] other object to compare to
59
- #
60
- # @return [Boolean] True if equals
61
- #
62
- def ==(other)
63
- (self <=> other).zero?
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreTypes::RefreshType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class RefreshType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::RewindFastforwardType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class RewindFastforwardType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
-
5
- module OpenHAB
6
- module DSL
7
- module MonkeyPatch
8
- #
9
- # Patches OpenHAB types
10
- #
11
- module Types
12
- java_import Java::OrgOpenhabCoreLibraryTypes::StopMoveType
13
-
14
- #
15
- # Monkey patch for DSL use
16
- #
17
- class StopMoveType
18
- alias inspect to_s
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Monkey patch types
4
- require 'openhab/dsl/monkey_patch/types/open_closed_type'
5
- require 'openhab/dsl/monkey_patch/types/on_off_type'
6
- require 'openhab/dsl/monkey_patch/types/decimal_type'
7
- require 'openhab/dsl/monkey_patch/types/increase_decrease_type'
8
- require 'openhab/dsl/monkey_patch/types/next_previous_type'
9
- require 'openhab/dsl/monkey_patch/types/percent_type'
10
- require 'openhab/dsl/monkey_patch/types/play_pause_type'
11
- require 'openhab/dsl/monkey_patch/types/quantity_type'
12
- require 'openhab/dsl/monkey_patch/types/refresh_type'
13
- require 'openhab/dsl/monkey_patch/types/rewind_fastforward_type'
14
- require 'openhab/dsl/monkey_patch/types/stop_move_type'
15
- require 'openhab/dsl/monkey_patch/types/up_down_type'
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
- module OpenHAB
5
- module DSL
6
- module MonkeyPatch
7
- #
8
- # Patches OpenHAB types
9
- #
10
- module Types
11
- java_import Java::OrgOpenhabCoreLibraryTypes::UpDownType
12
-
13
- #
14
- # MonkeyPatching UpDownType
15
- #
16
- class UpDownType
17
- #
18
- # Check if the supplied object is case equals to self
19
- #
20
- # @param [Object] other object to compare
21
- #
22
- # @return [Boolean] True if the other object is a RollershutterItem and has the same state
23
- #
24
- def ===(other)
25
- if other.respond_to?(:state)
26
- self == other.state&.as(UpDownType)
27
- elsif other.is_a? UpDownType
28
- self == other
29
- else
30
- super
31
- end
32
- end
33
-
34
- #
35
- # Test for equality
36
- #
37
- # @param [Object] other Other object to compare against
38
- #
39
- # @return [Boolean] true if self and other can be considered equal, false otherwise
40
- #
41
- def ==(other)
42
- if other.respond_to?(:get_state_as)
43
- self == other.get_state_as(UpDownType)
44
- else
45
- super
46
- end
47
- end
48
-
49
- #
50
- # Check if the state is UP
51
- #
52
- # @return [Boolean] true if UP, false otherwise
53
- #
54
- def up?
55
- self == UP
56
- end
57
-
58
- #
59
- # Check if the state is DOWN
60
- #
61
- # @return [Boolean] true if DOWN, false otherwise
62
- #
63
- def down?
64
- self == DOWN
65
- end
66
-
67
- alias inspect to_s
68
- end
69
- end
70
- end
71
- end
72
- end