openhab-scripting 4.1.4 → 4.2.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/entity_lookup.rb +1 -57
- data/lib/openhab/dsl/dsl.rb +6 -12
- data/lib/openhab/dsl/group.rb +1 -5
- data/lib/openhab/dsl/items/comparable_item.rb +49 -0
- data/lib/openhab/dsl/items/contact_item.rb +41 -0
- data/lib/openhab/dsl/items/date_time_item.rb +64 -0
- data/lib/openhab/dsl/items/dimmer_item.rb +59 -0
- data/lib/openhab/dsl/items/generic_item.rb +197 -0
- data/lib/openhab/dsl/items/group_item.rb +56 -92
- data/lib/openhab/dsl/items/image_item.rb +5 -41
- data/lib/openhab/dsl/items/item_registry.rb +49 -0
- data/lib/openhab/dsl/items/items.rb +71 -35
- data/lib/openhab/dsl/items/metadata.rb +325 -0
- data/lib/openhab/dsl/items/number_item.rb +6 -312
- data/lib/openhab/dsl/items/numeric_item.rb +66 -0
- data/lib/openhab/dsl/items/persistence.rb +122 -0
- data/lib/openhab/dsl/items/player_item.rb +49 -40
- data/lib/openhab/dsl/items/rollershutter_item.rb +25 -77
- data/lib/openhab/dsl/items/string_item.rb +16 -58
- data/lib/openhab/dsl/items/switch_item.rb +62 -0
- data/lib/openhab/dsl/lazy_array.rb +8 -6
- data/lib/openhab/dsl/monkey_patch/events/events.rb +2 -2
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +67 -24
- data/lib/openhab/dsl/monkey_patch/events/item_event.rb +5 -5
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +10 -11
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +10 -11
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +25 -2
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -3
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +24 -24
- data/lib/openhab/dsl/states.rb +1 -1
- data/lib/openhab/dsl/time_of_day.rb +3 -5
- data/lib/openhab/dsl/types/comparable_type.rb +21 -0
- data/lib/openhab/dsl/types/date_time_type.rb +334 -0
- data/lib/openhab/dsl/types/decimal_type.rb +187 -0
- data/lib/openhab/dsl/types/increase_decrease_type.rb +23 -0
- data/lib/openhab/dsl/types/next_previous_type.rb +23 -0
- data/lib/openhab/dsl/types/numeric_type.rb +39 -0
- data/lib/openhab/dsl/types/on_off_type.rb +29 -0
- data/lib/openhab/dsl/types/open_closed_type.rb +29 -0
- data/lib/openhab/dsl/types/percent_type.rb +68 -0
- data/lib/openhab/dsl/types/play_pause_type.rb +27 -0
- data/lib/openhab/dsl/types/quantity_type.rb +275 -0
- data/lib/openhab/dsl/types/refresh_type.rb +18 -0
- data/lib/openhab/dsl/types/rewind_fastforward_type.rb +33 -0
- data/lib/openhab/dsl/types/stop_move_type.rb +23 -0
- data/lib/openhab/dsl/types/string_type.rb +88 -0
- data/lib/openhab/dsl/types/type.rb +72 -0
- data/lib/openhab/dsl/types/types.rb +77 -0
- data/lib/openhab/dsl/types/un_def_type.rb +22 -0
- data/lib/openhab/dsl/types/up_down_type.rb +32 -0
- data/lib/openhab/dsl/units.rb +11 -6
- data/lib/openhab/version.rb +1 -1
- data/lib/openhab.rb +0 -1
- metadata +31 -28
- data/lib/openhab/dsl/items/datetime_item.rb +0 -75
- data/lib/openhab/dsl/items/item_command.rb +0 -90
- data/lib/openhab/dsl/items/item_delegate.rb +0 -125
- data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +0 -51
- data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +0 -140
- data/lib/openhab/dsl/monkey_patch/items/items.rb +0 -142
- data/lib/openhab/dsl/monkey_patch/items/metadata.rb +0 -328
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +0 -123
- data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +0 -71
- data/lib/openhab/dsl/monkey_patch/ruby/range.rb +0 -47
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -32
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +0 -97
- data/lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/next_previous_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +0 -79
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +0 -71
- data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +0 -77
- data/lib/openhab/dsl/monkey_patch/types/play_pause_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +0 -69
- data/lib/openhab/dsl/monkey_patch/types/refresh_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/stop_move_type.rb +0 -23
- data/lib/openhab/dsl/monkey_patch/types/types.rb +0 -15
- data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +0 -72
- data/lib/openhab/dsl/types/datetime.rb +0 -338
- data/lib/openhab/dsl/types/quantity.rb +0 -300
@@ -1,123 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenHAB
|
4
|
-
module DSL
|
5
|
-
module MonkeyPatch
|
6
|
-
module Items
|
7
|
-
#
|
8
|
-
# Persistence extension for Items
|
9
|
-
#
|
10
|
-
module Persistence
|
11
|
-
java_import Java::OrgOpenhabCoreTypesUtil::UnitUtils
|
12
|
-
|
13
|
-
# A wrapper for OpenHAB's HistoricItem that returns the state directly
|
14
|
-
class HistoricState < SimpleDelegator
|
15
|
-
attr_reader :timestamp, :state
|
16
|
-
|
17
|
-
def initialize(state, timestamp)
|
18
|
-
@state = state
|
19
|
-
@timestamp = timestamp
|
20
|
-
super(@state)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# All persistence methods that could return a Quantity
|
25
|
-
QUANTITY_METHODS = %i[average_since
|
26
|
-
delta_since
|
27
|
-
deviation_since
|
28
|
-
sum_since
|
29
|
-
variance_since].freeze
|
30
|
-
|
31
|
-
# All persistence methods that require a timestamp
|
32
|
-
PERSISTENCE_METHODS = (QUANTITY_METHODS +
|
33
|
-
%i[changed_since
|
34
|
-
evolution_rate
|
35
|
-
historic_state
|
36
|
-
maximum_since
|
37
|
-
minimum_since
|
38
|
-
updated_since]).freeze
|
39
|
-
|
40
|
-
%i[persist last_update].each do |method|
|
41
|
-
define_method(method) do |service = nil|
|
42
|
-
service ||= persistence_service
|
43
|
-
PersistenceExtensions.public_send(method, self, service&.to_s)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Return the previous state of the item
|
49
|
-
#
|
50
|
-
# @param skip_equal [Boolean] if true, skips equal state values and
|
51
|
-
# searches the first state not equal the current state
|
52
|
-
# @param service [String] the name of the PersistenceService to use
|
53
|
-
#
|
54
|
-
# @return the previous state or nil if no previous state could be found,
|
55
|
-
# or if the default persistence service is not configured or
|
56
|
-
# does not refer to a valid service
|
57
|
-
#
|
58
|
-
def previous_state(service = nil, skip_equal: false)
|
59
|
-
service ||= persistence_service
|
60
|
-
result = PersistenceExtensions.previous_state(self, skip_equal, service&.to_s)
|
61
|
-
HistoricState.new(quantify(result.state), result.timestamp)
|
62
|
-
end
|
63
|
-
|
64
|
-
PERSISTENCE_METHODS.each do |method|
|
65
|
-
define_method(method) do |timestamp, service = nil|
|
66
|
-
service ||= persistence_service
|
67
|
-
result = PersistenceExtensions.public_send(method, self, to_zdt(timestamp), service&.to_s)
|
68
|
-
if result.is_a? Java::OrgOpenhabCorePersistence::HistoricItem
|
69
|
-
return HistoricState.new(quantify(result.state), result.timestamp)
|
70
|
-
end
|
71
|
-
|
72
|
-
QUANTITY_METHODS.include?(method) ? quantify(result) : result
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
#
|
79
|
-
# Convert timestamp to ZonedDateTime if it's a TemporalAmount
|
80
|
-
#
|
81
|
-
# @param [Object] timestamp to convert
|
82
|
-
#
|
83
|
-
# @return [ZonedDateTime]
|
84
|
-
#
|
85
|
-
def to_zdt(timestamp)
|
86
|
-
if timestamp.is_a? Java::JavaTimeTemporal::TemporalAmount
|
87
|
-
logger.trace("Converting #{timestamp} (#{timestamp.class}) to ZonedDateTime")
|
88
|
-
Java::JavaTime::ZonedDateTime.now.minus(timestamp)
|
89
|
-
else
|
90
|
-
timestamp
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# Convert value to Quantity if it is a DecimalType and a unit is defined
|
96
|
-
#
|
97
|
-
# @param [Object] value The value to convert
|
98
|
-
#
|
99
|
-
# @return [Object] Quantity or the original value
|
100
|
-
#
|
101
|
-
def quantify(value)
|
102
|
-
if value.is_a?(Java::OrgOpenhabCoreLibraryTypes::DecimalType) && state_description&.pattern
|
103
|
-
item_unit = UnitUtils.parse_unit(state_description.pattern)
|
104
|
-
logger.trace("Unitizing #{value} with unit #{item_unit}")
|
105
|
-
Quantity.new(Java::OrgOpenhabCoreLibraryTypes::QuantityType.new(value.to_big_decimal, item_unit))
|
106
|
-
else
|
107
|
-
value
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Get the specified persistence service from the current thread local variable
|
113
|
-
#
|
114
|
-
# @return [Object] Persistence service name as String or Symbol, or nil if not set
|
115
|
-
#
|
116
|
-
def persistence_service
|
117
|
-
Thread.current.thread_variable_get(:persistence_service)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'java'
|
4
|
-
require 'openhab/dsl/items/item_command'
|
5
|
-
|
6
|
-
module OpenHAB
|
7
|
-
module DSL
|
8
|
-
module MonkeyPatch
|
9
|
-
#
|
10
|
-
# Patches OpenHAB items
|
11
|
-
#
|
12
|
-
module Items
|
13
|
-
java_import Java::OrgOpenhabCoreLibraryItems::SwitchItem
|
14
|
-
|
15
|
-
# Alias class names for easy is_a? comparisons
|
16
|
-
::Switch = SwitchItem
|
17
|
-
|
18
|
-
#
|
19
|
-
# Monkeypatching SwitchItem to add Ruby Support methods
|
20
|
-
#
|
21
|
-
class SwitchItem
|
22
|
-
extend OpenHAB::DSL::Items::ItemCommand
|
23
|
-
|
24
|
-
java_import Java::OrgOpenhabCoreLibraryTypes::OnOffType
|
25
|
-
|
26
|
-
item_type Java::OrgOpenhabCoreLibraryItems::SwitchItem
|
27
|
-
|
28
|
-
alias truthy? on?
|
29
|
-
|
30
|
-
#
|
31
|
-
# Send a command to invert the state of the switch
|
32
|
-
#
|
33
|
-
# @return [OnOffType] Inverted state
|
34
|
-
#
|
35
|
-
def toggle
|
36
|
-
self << !self
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Return the inverted state of the switch: ON if the switch is OFF, UNDEF or NULL; OFF if the switch is ON
|
41
|
-
#
|
42
|
-
# @return [OnOffType] Inverted state
|
43
|
-
#
|
44
|
-
def !
|
45
|
-
return !state if state?
|
46
|
-
|
47
|
-
OnOffType::ON
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Check for equality against supplied object
|
52
|
-
#
|
53
|
-
# @param [Object] other object to compare to
|
54
|
-
#
|
55
|
-
# @return [Boolean] True if other is a OnOffType and other equals state for this switch item,
|
56
|
-
# otherwise result from super
|
57
|
-
#
|
58
|
-
def ==(other)
|
59
|
-
other = other.get_state_as(OnOffType) if other.respond_to?(:get_state_as)
|
60
|
-
|
61
|
-
if other.is_a? OnOffType
|
62
|
-
state? && state == other
|
63
|
-
else
|
64
|
-
super
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
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 DSL
|
9
|
-
#
|
10
|
-
# MonkeyPatch both Ruby and OpenHAB Objects to support DSL
|
11
|
-
#
|
12
|
-
module MonkeyPatch
|
13
|
-
#
|
14
|
-
# MonkeyPatch ruby object to support DSL
|
15
|
-
#
|
16
|
-
module Ruby
|
17
|
-
#
|
18
|
-
# Extensions for Range Class to support DimmerItems
|
19
|
-
#
|
20
|
-
module RangeExtensions
|
21
|
-
java_import Java::OrgOpenhabCoreLibraryItems::DimmerItem
|
22
|
-
|
23
|
-
#
|
24
|
-
# Override range === method to support DimmerItems
|
25
|
-
#
|
26
|
-
# @param [Object] other object to compare for case equals
|
27
|
-
#
|
28
|
-
# @return [Boolean] if other is DimmerItem and state is covered by range,
|
29
|
-
# result from parent Range class if not DimmerItem
|
30
|
-
#
|
31
|
-
def ===(other)
|
32
|
-
return super unless other.is_a? DimmerItem
|
33
|
-
|
34
|
-
cover? other.state.to_i
|
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::DSL::MonkeyPatch::Ruby::RangeExtensions
|
47
|
-
end
|
@@ -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
|