openhab-scripting 3.3.0 → 3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01e9ddbd43a59fec9db3fa391d42cacb0cd1a03c7d116e995815df940847b28b
4
- data.tar.gz: ef98bb992444788122499056470c2fde3fbfbdb6659a72228df0f2c46bd8cecb
3
+ metadata.gz: 0cfe54bca7a28404b0011b2b3686d0617558a4567fe620f847bb14497e9d1604
4
+ data.tar.gz: b8716022904648f8d0898d7866de3b7091e5890b8e5c3ccd53ea192467116d6b
5
5
  SHA512:
6
- metadata.gz: 4499127b7c667c3290eb3d106624649ff04eff597eb95668c868bcaf5236f99a9149adf4b74e4750e2d092bc5cd7c3cc8b56b6470968f34c6324985b8bec7472
7
- data.tar.gz: 93a18bda44e472326eb5952d089f5a8eb1f221bc566c861c9abee4cce08c21b5a8d29aa5168b05c5c54c3e61e613e1834ff01c39f18f57dcc2efc8d4c9eacbb5
6
+ metadata.gz: 1a8256023fc3a4504d7ee410c5bba1b784bb197736c5dd84a07e2fd6a289062e905503e04c88c2302138eb561bb82ac0566315f4d75bca417f88818dc57f0326
7
+ data.tar.gz: 4e4f81238fd24e824a3c255d9f96b2ad0d386efb9d663639ef7c085a89692eb5f3d68698caa5ebc8137050586bf5d8ad721f3d72925e4e0ab3fcedef1ce1ba5a
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'base64'
4
+ require 'pathname'
4
5
  require 'net/http'
5
6
  require 'java'
6
- require 'mimemagic'
7
+ require 'marcel'
7
8
  require 'openhab/dsl/items/item_command'
8
9
  require 'openhab/dsl/items/item_delegate'
9
10
 
@@ -57,7 +58,7 @@ module OpenHAB
57
58
  #
58
59
  def update_from_file(file, mime_type: nil)
59
60
  file_data = IO.binread(file)
60
- mime_type ||= (MimeMagic.by_path(file) || MimeMagic.by_magic(file_data))&.type
61
+ mime_type ||= Marcel::MimeType.for(Pathname.new(file)) || Marcel::MimeType.for(file_data)
61
62
  update_from_bytes(file_data, mime_type: mime_type)
62
63
  end
63
64
 
@@ -130,7 +131,7 @@ module OpenHAB
130
131
  #
131
132
  def detect_mime_from_bytes(bytes:)
132
133
  logger.trace('Detecting mime type from file image contents')
133
- MimeMagic.by_magic(bytes)&.type
134
+ Marcel::MimeType.for(bytes)
134
135
  end
135
136
  end
136
137
  end
@@ -41,6 +41,7 @@ module OpenHAB
41
41
  logger.trace("Creating delegate for (#{method}) to #{item}) for #{self.class}")
42
42
  def_delegator item, method
43
43
  end
44
+ define_method(:oh_item) { instance_variable_get(item) }
44
45
  end
45
46
 
46
47
  #
@@ -30,7 +30,7 @@ module OpenHAB
30
30
 
31
31
  def initialize(metadata: nil, key: nil, value: nil, config: nil)
32
32
  @metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value&.to_s, config)
33
- super(@metadata&.configuration)
33
+ super(to_ruby(@metadata&.configuration))
34
34
  end
35
35
 
36
36
  #
@@ -85,6 +85,44 @@ module OpenHAB
85
85
  def to_a
86
86
  [@metadata&.value, @metadata&.configuration || {}]
87
87
  end
88
+
89
+ private
90
+
91
+ #
92
+ # Recursively convert the supplied Hash object into a Ruby Hash and recreate the keys and values
93
+ #
94
+ # @param [Hash] Hash to convert
95
+ #
96
+ # @return [Hash] The converted hash
97
+ #
98
+ def to_ruby_hash(hash)
99
+ return unless hash.respond_to? :each_with_object
100
+
101
+ hash.each_with_object({}) { |(key, value), ruby_hash| ruby_hash[to_ruby(key)] = to_ruby(value) }
102
+ end
103
+
104
+ #
105
+ # Recursively convert the supplied array to a Ruby array and recreate all String values
106
+ #
107
+ # @param [Object] array to convert
108
+ #
109
+ # @return [Array] The converted array
110
+ #
111
+ def to_ruby_array(array)
112
+ return unless array.respond_to? :each_with_object
113
+
114
+ array.each_with_object([]) { |value, ruby_array| ruby_array << to_ruby(value) }
115
+ end
116
+
117
+ # Convert the given object to Ruby equivalent
118
+ def to_ruby(value)
119
+ case value
120
+ when Hash, Java::JavaUtil::Map then to_ruby_hash(value)
121
+ when Array, Java::JavaUtil::List then to_ruby_array(value)
122
+ when String then String.new(value)
123
+ else value
124
+ end
125
+ end
88
126
  end
89
127
 
90
128
  #
@@ -30,11 +30,8 @@ module OpenHAB
30
30
  dow: '?'
31
31
  }
32
32
  end
33
- # Rubocop check is disabled because YARD cannot process the method if placed in front of
34
- # the method definition
35
- # rubocop:disable Style/AccessModifierDeclarations
33
+
36
34
  module_function :cron_expression_map
37
- # rubocop:enable Style/AccessModifierDeclarations
38
35
 
39
36
  # @return [Hash] Map of days of the week from symbols to to OpenHAB cron strings
40
37
  DAY_OF_WEEK_MAP = {
@@ -48,7 +48,8 @@ module OpenHAB
48
48
  # @return [StateStorage] item states
49
49
  #
50
50
  def store_states(*items)
51
- states = StateStorage.new(BusEvent.storeStates(*items.flatten).to_h)
51
+ items = items.flatten.map { |item| item.respond_to?(:oh_item) ? item.oh_item : item }
52
+ states = StateStorage.new(BusEvent.storeStates(*items).to_h)
52
53
  if block_given?
53
54
  yield
54
55
  states.restore
@@ -11,6 +11,7 @@ module OpenHAB
11
11
  # Support for OpenHAB Things
12
12
  #
13
13
  module Things
14
+ java_import Java::OrgOpenhabCoreThing::ThingStatus
14
15
  include OpenHAB::Log
15
16
 
16
17
  #
@@ -25,6 +26,22 @@ module OpenHAB
25
26
  define_action_methods
26
27
  end
27
28
 
29
+ #
30
+ # Defines boolean thing status methods
31
+ # uninitialized?
32
+ # initializing?
33
+ # unknown?
34
+ # online?
35
+ # offline?
36
+ # removing?
37
+ # removed?
38
+ #
39
+ # @return [Boolean] true if the thing status matches the name
40
+ #
41
+ ThingStatus.constants.each do |thingstatus|
42
+ define_method("#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
43
+ end
44
+
28
45
  private
29
46
 
30
47
  java_import 'org.openhab.core.automation.annotation.RuleAction'
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '3.3.0'
8
+ VERSION = '3.5.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.3.0
4
+ version: 3.5.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-03-16 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: mimemagic
28
+ name: marcel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '1.0'
41
41
  description: JRuby Helper Libraries for OpenHAB Scripting
42
42
  email:
43
43
  - broconne@gmail.com
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.7.6.2
136
+ rubygems_version: 2.7.6.3
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: JRuby Helper Libraries for OpenHAB Scripting