openhab-scripting 2.26.1 → 2.27.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e85c64c68c9d566c3c4cf1070ea994fae3e3b57dda312c0854da87bff393ae1c
4
- data.tar.gz: 9934d415111e5a680f1a8a7630ef1b08e0ed537cc537631100ee3dd73b1ce70d
3
+ metadata.gz: 2076584e55cc649fda227034943f6a412fb7a43a52479aec0ff3f33452266cc4
4
+ data.tar.gz: a7eb3154b9f436987883106bd39ab2a6574190abd2236d7c4898420624cbea87
5
5
  SHA512:
6
- metadata.gz: dfe0d9a8e3ec9a4e4ed2121958d508f3ce0d552db041dbfa8099168f4e2963f5c823b68931a04a796d7311f138fcd64fd8733ad81ef859b7d8b751526e52cc1c
7
- data.tar.gz: 440dd0f36d20abf8a27cab1b87f5f73c90c7b852ed7496fdfb2abd3f6d7e76add9fbf6f6c5ecccfad125a6e56182ba85839d2d14e218037d9ad073648226afe4
6
+ metadata.gz: 5e1923dd15436484c0bd72c9aa83ab4a72d554e7cc17c7d9c06e4eda0b335a13b283405acdf8282e75bb1488c245c890b9b7151c0de03f8316d6367ad7e5be6f
7
+ data.tar.gz: f7e218fbf8b28b27ef154bcfa42dc167f0cf4bede89fe4772489a4aa8cec77d9827be83d32e748b663876a5286649217322d840b638ea73a37200ef82cfe34a9
@@ -87,25 +87,25 @@ module OpenHAB
87
87
  # @return [Object] the ruby wrapper for the item
88
88
  #
89
89
  # rubocop: disable Metrics/MethodLength
90
- # rubocop: disable Metrics/AbcSize
91
90
  # Disabled line length and branch size - case dispatch pattern
92
91
  private_class_method def self.decorate_item(item)
93
92
  case item
94
93
  when GroupItem
95
94
  decorate_group(item)
96
- when Java::Org.openhab.core.library.items::NumberItem
95
+ when Java::OrgOpenhabCoreLibraryItems::NumberItem
97
96
  OpenHAB::DSL::Items::NumberItem.new(item)
98
- when Java::Org.openhab.core.library.items::StringItem
97
+ when Java::OrgOpenhabCoreLibraryItems::StringItem
99
98
  OpenHAB::DSL::Items::StringItem.new(item)
100
- when Java::Org.openhab.core.library.items::DateTimeItem
99
+ when Java::OrgOpenhabCoreLibraryItems::DateTimeItem
101
100
  OpenHAB::DSL::Items::DateTimeItem.new(item)
102
- when Java::Org.openhab.core.library.items::RollershutterItem
101
+ when Java::OrgOpenhabCoreLibraryItems::RollershutterItem
103
102
  OpenHAB::DSL::Items::RollershutterItem.new(item)
103
+ when Java::OrgOpenhabCoreLibraryItems::PlayerItem
104
+ OpenHAB::DSL::Items::PlayerItem.new(item)
104
105
  else
105
106
  item
106
107
  end
107
108
  end
108
- # rubocop: enable Metrics/AbcSize
109
109
  # rubocop: enable Metrics/MethodLength
110
110
 
111
111
  #
@@ -15,6 +15,7 @@ require 'openhab/dsl/things'
15
15
  require 'openhab/dsl/items/items'
16
16
  require 'openhab/dsl/items/datetime_item'
17
17
  require 'openhab/dsl/items/number_item'
18
+ require 'openhab/dsl/items/player_item'
18
19
  require 'openhab/dsl/time_of_day'
19
20
  require 'openhab/dsl/gems'
20
21
  require 'openhab/dsl/persistence'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'java'
4
+ require 'openhab/log/logger'
4
5
 
5
6
  module OpenHAB
6
7
  module DSL
@@ -9,19 +10,25 @@ module OpenHAB
9
10
  # Holds methods to automatically generate commands and
10
11
  # accessors for items
11
12
  module ItemCommand
13
+ include OpenHAB::Log
14
+
12
15
  #
13
16
  # For every value in the supplied enumeration create a corresponding method mapped to the lowercase
14
17
  # string representation of the enum value For example, an enum with values of STOP and START
15
18
  # would create methods stop() and start() that send the corresponding STOP and START commands to the item
16
19
  #
17
20
  # @param [Java::JavaLang::Enum] command_enum Enumeration to create commands for
21
+ # @param [Hash] optional hash in which if a generated method name mactches a key, the value of that key
22
+ # will be used as the method name instead, for example `:play? => :playing?`
18
23
  #
19
24
  #
20
- def item_command(command_enum)
25
+ def item_command(command_enum, methods = {})
21
26
  # rubocop:disable Style/HashEachMethods
22
27
  # Disable rule because Java enum does not support each_value
23
28
  command_enum.values.each do |command|
24
29
  command_method = command.to_s.downcase
30
+ 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}")
25
32
  define_method(command_method) do
26
33
  self.command(command)
27
34
  end
@@ -37,14 +44,17 @@ module OpenHAB
37
44
  #
38
45
  # @param [Java::JavaLang::Enum] command_enum Enumeration to create methods for each value
39
46
  # to check if current state matches that enum
40
- # @yield [state] Optional block that can be used to transform state prior to comparison
47
+ # @param [Hash] optional hash in which if a generated method name mactches a key, the value of that key
48
+ # will be used as the method name instead, for example `:play? => :playing?`
41
49
  #
42
50
  #
43
- def item_state(command_enum)
51
+ def item_state(command_enum, methods = {})
44
52
  # rubocop:disable Style/HashEachMethods
45
53
  # Disable rule because Java enum does not support each_value
46
54
  command_enum.values.each do |command|
47
55
  status_method = "#{command.to_s.downcase}?"
56
+ 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}")
48
58
  define_method(status_method) do
49
59
  state? && state.as(command_enum) == command
50
60
  end
@@ -57,14 +67,18 @@ module OpenHAB
57
67
  # Item class and pass them to item_state/item_command
58
68
  #
59
69
  # @param [Java::JavaLang::Class] item_class a Class that implements Java::OrgOpenhabCoreItems::Item
70
+ # @param [Hash] optional hash in which if a generated method name mactches a key, the value of that key
71
+ # will be used as the method name instead, for example `:play? => :playing?`
60
72
  #
61
- def item_type(item_class)
73
+ def item_type(item_class, methods = {})
62
74
  item_class.field_reader(:ACCEPTED_DATA_TYPES)
63
75
  item_class.field_reader(:ACCEPTED_COMMAND_TYPES)
64
- item_class.ACCEPTED_DATA_TYPES.select(&:is_enum).grep_v(UnDefType).each { |type| item_state(type.ruby_class) }
65
- item_class.ACCEPTED_COMMAND_TYPES.select(&:is_enum).grep_v(UnDefType).each do |type|
66
- item_command(type.ruby_class)
67
- end
76
+ item_class.ACCEPTED_DATA_TYPES.select(&:is_enum)
77
+ .grep_v(UnDefType)
78
+ .each { |type| item_state(type.ruby_class, methods) }
79
+ item_class.ACCEPTED_COMMAND_TYPES.select(&:is_enum)
80
+ .grep_v(UnDefType)
81
+ .each { |type| item_command(type.ruby_class, methods) }
68
82
  end
69
83
  end
70
84
  end
@@ -33,7 +33,7 @@ module OpenHAB
33
33
  alias key? include?
34
34
  end
35
35
 
36
- java_import org.openhab.core.items.GroupItem
36
+ java_import Java::OrgOpenhabCoreItems::GroupItem
37
37
  # Fetches all non-group items from the item registry
38
38
  # @return [OpenHAB::DSL::Items::Items]
39
39
  def items
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'java'
5
+ require 'openhab/dsl/items/item_command'
6
+ require 'openhab/dsl/items/item_delegate'
7
+
8
+ module OpenHAB
9
+ module DSL
10
+ module Items
11
+ #
12
+ # Delegator to OpenHAB Player Item
13
+ #
14
+ class PlayerItem
15
+ extend OpenHAB::DSL::Items::ItemCommand
16
+ extend OpenHAB::DSL::Items::ItemDelegate
17
+ extend Forwardable
18
+
19
+ def_item_delegator :@player_item
20
+
21
+ item_type Java::OrgOpenhabCoreLibraryItems::PlayerItem, play?: :playing?, pause?: :paused?,
22
+ rewind?: :rewinding?, fastforward?: :fastforwarding?
23
+
24
+ # rubocop: disable Style/Alias
25
+ # Disabled because 'alias' does not work with the dynamically defined methods
26
+ alias_method :fast_forward, :fastforward
27
+ alias_method :fast_forwarding?, :fastforwarding?
28
+ # rubocop: enable Style/Alias
29
+
30
+ #
31
+ # Creates a new PlayerItem
32
+ #
33
+ # @param [Java::OrgOpenhabCoreLibraryItems::PlayerItem] player_item
34
+ # The OpenHAB PlayerItem to delegate to
35
+ #
36
+ def initialize(player_item)
37
+ logger.trace("Wrapping #{player_item}")
38
+ @player_item = player_item
39
+
40
+ item_missing_delegate { @player_item }
41
+
42
+ super()
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '2.26.1'
8
+ VERSION = '2.27.0'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.26.1
4
+ version: 2.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -44,6 +44,7 @@ files:
44
44
  - lib/openhab/dsl/items/item_delegate.rb
45
45
  - lib/openhab/dsl/items/items.rb
46
46
  - lib/openhab/dsl/items/number_item.rb
47
+ - lib/openhab/dsl/items/player_item.rb
47
48
  - lib/openhab/dsl/items/rollershutter_item.rb
48
49
  - lib/openhab/dsl/items/string_item.rb
49
50
  - lib/openhab/dsl/monkey_patch/actions/actions.rb