openhab-scripting 3.9.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 356cf9cd952afd9acdbdb1ee202360b5403b45f252763a5bf9cdfbb3b48f80d6
4
- data.tar.gz: 813a84b33014c8c6248b7084140c412582d3889226caf08de9e1160452cd50ff
3
+ metadata.gz: bf75e647f468a653d6848739cf2552ba57b9d1b1d81f33eed2f3719315d28d11
4
+ data.tar.gz: 8f6403a4642e1edd1eb3047d438939b5d127c0fd0eca57c8989e9a72bf0bdb39
5
5
  SHA512:
6
- metadata.gz: 739813b353f513abdb50afff61047f75a7ae96e26b42bf6381e039ef3c35ca7535f696475ccbd999bb79925bee83ecb412533306ce4f7af8566c2a22db4fab8f
7
- data.tar.gz: 443ad43667b89e0231247879e5dc9eddcf479b9ef2f05f09c08a931e1b13e2a96b1075c2870c95cb608c021e84b17e72850d9b5fb6e7c174f5bfee0d82e86522
6
+ metadata.gz: 9e0ea6a8962334965162c95ff2db82a3fcf0485c6b80fefd2ea0814d0883678052bd52306093ea70e2cb0aec9e3fb8df42fd9290f9b9b21ddfb71db11649f104
7
+ data.tar.gz: 4d492998dd50c6b25fd845df988d7ef418e5d2a8a66c339bf5fabf990cd6380d6a588ee6fc899d47d697564b78c88397a77d362a39da0a6d7f9d7ba3c99d4c71
@@ -68,6 +68,7 @@ module OpenHAB
68
68
  def members
69
69
  GroupMembers.new(@group_item)
70
70
  end
71
+ alias items members
71
72
 
72
73
  #
73
74
  # Iterates through the direct members of the Group
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'java'
4
4
  require 'openhab/log/logger'
5
+ require 'openhab/dsl/monkey_patch/events/item_command'
5
6
 
6
7
  module OpenHAB
7
8
  module DSL
@@ -28,7 +29,7 @@ module OpenHAB
28
29
  command_enum.values.each do |command|
29
30
  command_method = command.to_s.downcase
30
31
  command_method = methods.transform_keys(&:to_sym).fetch(command_method.to_sym, command_method)
31
- logger.trace("Creating command method (#{command_method}) for #{self.class}")
32
+ logger.trace("Creating command method (#{command_method}) for #{self}")
32
33
  define_method(command_method) do
33
34
  self.command(command)
34
35
  end
@@ -54,7 +55,7 @@ module OpenHAB
54
55
  command_enum.values.each do |command|
55
56
  status_method = "#{command.to_s.downcase}?"
56
57
  status_method = methods.transform_keys(&:to_sym).fetch(status_method.to_sym, status_method)
57
- logger.trace("Creating status method (#{status_method}) for #{self.class}")
58
+ logger.trace("Creating status method (#{status_method}) for #{self}")
58
59
  define_method(status_method) do
59
60
  state? && state.as(command_enum) == command
60
61
  end
@@ -70,7 +71,7 @@ module OpenHAB
70
71
  # @param [Hash] optional hash in which if a generated method name mactches a key, the value of that key
71
72
  # will be used as the method name instead, for example `:play? => :playing?`
72
73
  #
73
- def item_type(item_class, methods = {})
74
+ def item_type(item_class, methods = {}) # rubocop:disable Metrics/MethodLength
74
75
  item_class.field_reader(:ACCEPTED_DATA_TYPES)
75
76
  item_class.field_reader(:ACCEPTED_COMMAND_TYPES)
76
77
  item_class.ACCEPTED_DATA_TYPES.select(&:is_enum)
@@ -78,7 +79,10 @@ module OpenHAB
78
79
  .each { |type| item_state(type.ruby_class, methods) }
79
80
  item_class.ACCEPTED_COMMAND_TYPES.select(&:is_enum)
80
81
  .grep_v(UnDefType)
81
- .each { |type| item_command(type.ruby_class, methods) }
82
+ .each do |type|
83
+ item_command(type.ruby_class, methods)
84
+ MonkeyPatch::Events::ItemCommandEvent.def_enum_predicates(type.ruby_class)
85
+ end
82
86
  end
83
87
  end
84
88
  end
@@ -15,7 +15,26 @@ module OpenHAB
15
15
  # Monkey patch with ruby style accesors
16
16
  #
17
17
  class ItemCommandEvent
18
+ include Log
19
+
18
20
  alias command item_command
21
+
22
+ #
23
+ # For every value in the supplied enumeration create a corresponding method mapped to the lowercase
24
+ # string representation of the enum value For example, an enum with values of STOP and START
25
+ # would create methods stop? and start? that check if the command is corresponding STOP and START type
26
+ #
27
+ # @param [Java::JavaLang::Enum] command_enum Enumeration to create commands for
28
+ #
29
+ def self.def_enum_predicates(command_enum)
30
+ command_enum.values.each do |command| # rubocop:disable Style/HashEachMethods : Java enum does not have each_value
31
+ command_method = "#{command.to_s.downcase}?"
32
+ logger.trace("Creating predicate method (#{command_method}) for #{self}")
33
+ define_method(command_method) do
34
+ self.command == command
35
+ end
36
+ end
37
+ end
19
38
  end
20
39
  end
21
40
  end
@@ -10,12 +10,51 @@ module OpenHAB
10
10
  #
11
11
  module Events
12
12
  java_import Java::OrgOpenhabCoreItemsEvents::ItemStateEvent
13
+ java_import Java::OrgOpenhabCoreTypes::UnDefType
14
+
15
+ # Helpers common to ItemStateEvent and ItemStateChangedEvent
16
+ module ItemStateUnDefTypeHelpers
17
+ #
18
+ # Check if the state == UNDEF
19
+ #
20
+ # @return [Boolean] True if the state is UNDEF, false otherwise
21
+ #
22
+ def undef?
23
+ item_state == UnDefType::UNDEF
24
+ end
25
+
26
+ #
27
+ # Check if the state == NULL
28
+ #
29
+ # @return [Boolean] True if the state is NULL, false otherwise
30
+ def null?
31
+ item_state == UnDefType::NULL
32
+ end
33
+
34
+ #
35
+ # Check if the state is defined (not UNDEF or NULL)
36
+ #
37
+ # @return [Boolean] True if state is not UNDEF or NULL
38
+ #
39
+ def state?
40
+ undef? == false && null? == false
41
+ end
42
+
43
+ #
44
+ # Get the item state
45
+ #
46
+ # @return [State] OpenHAB state if state is not UNDEF or NULL, nil otherwise
47
+ #
48
+ def state
49
+ item_state if state?
50
+ end
51
+ end
13
52
 
14
53
  #
15
54
  # MonkeyPatch with ruby style accessors
16
55
  #
17
56
  class ItemStateEvent
18
- alias state item_state
57
+ include ItemStateUnDefTypeHelpers
19
58
  end
20
59
  end
21
60
  end
@@ -10,13 +10,50 @@ module OpenHAB
10
10
  #
11
11
  module Events
12
12
  java_import Java::OrgOpenhabCoreItemsEvents::ItemStateChangedEvent
13
+ java_import Java::OrgOpenhabCoreTypes::UnDefType
13
14
 
14
15
  #
15
16
  # MonkeyPatch with ruby style accessors
16
17
  #
17
18
  class ItemStateChangedEvent
18
- alias state item_state
19
- alias last old_item_state
19
+ include ItemStateUnDefTypeHelpers
20
+
21
+ #
22
+ # Check if state was == UNDEF
23
+ #
24
+ # @return [Boolean] True if the state is UNDEF, false otherwise
25
+ #
26
+ def was_undef?
27
+ old_item_state == UnDefType::UNDEF
28
+ end
29
+
30
+ #
31
+ # Check if state was == NULL
32
+ #
33
+ # @return [Boolean] True if the state is NULL, false otherwise
34
+ def was_null?
35
+ old_item_state == UnDefType::NULL
36
+ end
37
+
38
+ #
39
+ # Check if state was defined (not UNDEF or NULL)
40
+ #
41
+ # @return [Boolean] True if state is not UNDEF or NULL
42
+ #
43
+ def was?
44
+ was_undef? == false && was_null? == false
45
+ end
46
+
47
+ #
48
+ # Get the previous item state
49
+ #
50
+ # @return [State] OpenHAB state if state was not UNDEF or NULL, nil otherwise
51
+ #
52
+ def was
53
+ old_item_state if was?
54
+ end
55
+
56
+ alias last was
20
57
  end
21
58
  end
22
59
  end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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
@@ -33,16 +33,9 @@ module OpenHAB
33
33
  # nil if object cannot be compared
34
34
  #
35
35
  def ===(other)
36
- # A case statement here causes and infinite loop
37
- # rubocop:disable Style/CaseLikeIf
38
- if self == ON
39
- other.on? if other.respond_to? :on?
40
- elsif self == OFF
41
- other.off? if other.respond_to?('off?')
42
- else
43
- false
44
- end
45
- # rubocop:enable Style/CaseLikeIf
36
+ (on? && other.respond_to?(:on?) && other.on?) ||
37
+ (off? && other.respond_to?(:off?) && other.off?) ||
38
+ super
46
39
  end
47
40
 
48
41
  #
@@ -59,6 +52,26 @@ module OpenHAB
59
52
  super
60
53
  end
61
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
62
75
  end
63
76
  end
64
77
  end
@@ -25,13 +25,9 @@ module OpenHAB
25
25
  # @return [Boolean] True if the other object is a ContactItem and has the same state
26
26
  #
27
27
  def ===(other)
28
- if other.respond_to?(:state)
29
- self == other.state
30
- elsif other.is_a? OpenClosedType
31
- self == other
32
- else
28
+ (open? && other.respond_to?(:open?) && other.open?) ||
29
+ (closed? && other.respond_to?(:closed?) && other.closed?) ||
33
30
  super
34
- end
35
31
  end
36
32
 
37
33
  #
@@ -48,6 +44,26 @@ module OpenHAB
48
44
  super
49
45
  end
50
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
51
67
  end
52
68
  end
53
69
  end
@@ -25,6 +25,51 @@ module OpenHAB
25
25
  super
26
26
  end
27
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
28
73
  end
29
74
  end
30
75
  end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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
@@ -4,6 +4,12 @@
4
4
  require 'openhab/dsl/monkey_patch/types/open_closed_type'
5
5
  require 'openhab/dsl/monkey_patch/types/on_off_type'
6
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'
7
9
  require 'openhab/dsl/monkey_patch/types/percent_type'
10
+ require 'openhab/dsl/monkey_patch/types/play_pause_type'
8
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'
9
15
  require 'openhab/dsl/monkey_patch/types/up_down_type'
@@ -45,6 +45,26 @@ module OpenHAB
45
45
  super
46
46
  end
47
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
48
68
  end
49
69
  end
50
70
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '3.9.4'
8
+ VERSION = '4.0.0'
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.4
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-25 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,10 +84,16 @@ files:
84
84
  - lib/openhab/dsl/monkey_patch/ruby/string.rb
85
85
  - lib/openhab/dsl/monkey_patch/ruby/time.rb
86
86
  - lib/openhab/dsl/monkey_patch/types/decimal_type.rb
87
+ - lib/openhab/dsl/monkey_patch/types/increase_decrease_type.rb
88
+ - lib/openhab/dsl/monkey_patch/types/next_previous_type.rb
87
89
  - lib/openhab/dsl/monkey_patch/types/on_off_type.rb
88
90
  - lib/openhab/dsl/monkey_patch/types/open_closed_type.rb
89
91
  - lib/openhab/dsl/monkey_patch/types/percent_type.rb
92
+ - lib/openhab/dsl/monkey_patch/types/play_pause_type.rb
90
93
  - lib/openhab/dsl/monkey_patch/types/quantity_type.rb
94
+ - lib/openhab/dsl/monkey_patch/types/refresh_type.rb
95
+ - lib/openhab/dsl/monkey_patch/types/rewind_fastforward_type.rb
96
+ - lib/openhab/dsl/monkey_patch/types/stop_move_type.rb
91
97
  - lib/openhab/dsl/monkey_patch/types/types.rb
92
98
  - lib/openhab/dsl/monkey_patch/types/up_down_type.rb
93
99
  - lib/openhab/dsl/persistence.rb