openhab-scripting 4.21.0 → 4.23.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: 330baeb4ed7472cdf6c60ba060d0b4482f988fa72c8ff0dd33b00c3e2df28b4a
4
- data.tar.gz: 35cab5382ecb542fcc90f02200c8ac977ccf4c1c880e2b644df2715c11fc36b1
3
+ metadata.gz: 6a1dda09cc4876b335d5da064fa1e19a1196f56d030225e96f6c6efe0c22d3f6
4
+ data.tar.gz: 23cac17429e99d6757db5f7232e53f8d77a656fb9bfb15d2ee4984fde63d691c
5
5
  SHA512:
6
- metadata.gz: a8c14ed23a21431328a55326313c06d16fdd0447426e741270d2f26ada96dee1425fb8e30da96b6d515b6c1406392ec56c2d3e598f5822b0a528273bacbbf441
7
- data.tar.gz: 265d8939f4c02ccd883c006903d759c8f5208c6c80035a831344055c44c94880e703f76830ecd535464a8cbddd0d4e543cf5af23e35f379b3c532c9525cc9f2f
6
+ metadata.gz: 5e473c9f0e2764d041613fd728377895430e790846986d3aca9b508f1ef3c0999c72473402cc0094d42c866871fa3161daeb0d4eedc3173b5485e9e33ab9f979
7
+ data.tar.gz: fdddf783a82f71c0e1364f47f8397daa394ded4935bd16f7746000f9c6f466db074000a2bf065ee1f1daf05f43f1fa1a3d94db3169144cadc7cb2114b5a96a36
@@ -48,10 +48,51 @@ module OpenHAB
48
48
  # convert it to an HSBType
49
49
  # @!visibility private
50
50
  def format_type(command)
51
+ return format_hash(command.to_hash) if command.respond_to?(:to_hash)
51
52
  return Types::HSBType.new(command) if command.respond_to?(:to_str)
52
53
 
53
54
  super
54
55
  end
56
+
57
+ #
58
+ # Convert the ColorItem to a hash
59
+ # @param [:hsb, :rgb] format for hash
60
+ # @return [Hash] in requested format
61
+ def to_h(format = :hsb)
62
+ values = to_a(format)
63
+ keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
64
+ keys.zip(values).to_h
65
+ end
66
+
67
+ #
68
+ # Convert the ColorItem to an array of values
69
+ # @param [:hsb, :rgb] format for elements in the array
70
+ # @return [Array] of ColorItem components in requested format
71
+ def to_a(format = :hsb)
72
+ case format
73
+ when :hsb then [hue, saturation, brightness]
74
+ when :rgb then [red, green, blue].map(&:to_byte)
75
+ else
76
+ raise ArgumentError, "Unsupported format #{format}"
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ # Mapping of hash values sets to conversion methods
83
+ HASH_KEYS = { %i[r g b] => :from_rgb,
84
+ %i[red green blue] => :from_rgb,
85
+ %i[h s b] => :from_hsb,
86
+ %i[hue saturation brightness] => :from_hsb }.freeze
87
+
88
+ def format_hash(hash)
89
+ hash = hash.transform_keys(&:to_sym)
90
+ HASH_KEYS.each do |key_set, method|
91
+ values = hash.values_at(*key_set).compact
92
+ return Types::HSBType.public_send(method, *values) if values.length == 3
93
+ end
94
+ raise ArgumentError, "Supplied hash (#{hash}) must contain one of the following keysets #{keys.keys}"
95
+ end
55
96
  end
56
97
  end
57
98
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'forwardable'
4
4
  require 'time'
5
+ require 'java'
5
6
 
6
7
  require 'openhab/dsl/items/comparable_item'
7
8
 
@@ -9,6 +10,7 @@ module OpenHAB
9
10
  module DSL
10
11
  module Items
11
12
  java_import org.openhab.core.library.items.DateTimeItem
13
+ java_import java.time.format.DateTimeFormatter
12
14
 
13
15
  # Adds methods to core OpenHAB DateTimeItem type to make it more natural
14
16
  # in Ruby
@@ -53,6 +55,7 @@ module OpenHAB
53
55
  # @!visibility private
54
56
  def format_type(command)
55
57
  return command.iso8601 if command.respond_to?(:iso8601)
58
+ return DateTimeFormatter::ISO_OFFSET_DATE_TIME.format(command) if command.is_a? java.time.ZonedDateTime
56
59
 
57
60
  super
58
61
  end
@@ -152,7 +152,7 @@ module OpenHAB
152
152
  @thread_locals = Thread.current[:RULE_NAME] ? { RULE_NAME: Thread.current[:RULE_NAME] } : {}
153
153
  set_name("Cancels implicit timer for #{timed_command_details.item.id}")
154
154
  set_triggers([OpenHAB::DSL::Rules::Triggers::Trigger.trigger(
155
- type: OpenHAB::DSL::Rules::Triggers::Trigger::ITEM_STATE_UPDATE,
155
+ type: OpenHAB::DSL::Rules::Triggers::Trigger::ITEM_STATE_CHANGE,
156
156
  config: { 'itemName' => timed_command_details.item.name }
157
157
  )])
158
158
  end
@@ -107,10 +107,13 @@ module OpenHAB
107
107
  # Extend MonthDay java object with some helper methods
108
108
  class MonthDay
109
109
  include OpenHAB::Log
110
+ java_import java.time.format.DateTimeFormatter
110
111
  # Parse MonthDay string as defined with by Monthday class without leading double dash "--"
111
112
  def self.parse(string)
112
- ## string = "--#{string}" unless string.to_s.start_with? '--'
113
- java_send :parse, [java.lang.CharSequence], "--#{string}"
113
+ logger.trace("#{self.class}.parse #{string} (#{string.class})")
114
+ java_send :parse, [java.lang.CharSequence, java.time.format.DateTimeFormatter],
115
+ string.to_s,
116
+ DateTimeFormatter.ofPattern('[--]M-d')
114
117
  end
115
118
 
116
119
  # Can the supplied object be parsed into a MonthDay
@@ -123,6 +126,9 @@ module OpenHAB
123
126
  to_string.delete_prefix('--')
124
127
  end
125
128
 
129
+ # remove the inherited #== method to use our <=> below
130
+ remove_method :==
131
+
126
132
  # Extends MonthDay comparison to support Strings
127
133
  # Necessary to support mixed ranges of Strings and MonthDay types
128
134
  # @return [Number, nil] -1,0,1 if other MonthDay is less than, equal to, or greater than this MonthDay
@@ -47,7 +47,7 @@ module OpenHAB
47
47
  # @param saturation [PercentType, Numeric] Saturation component (0-100%)
48
48
  # @param brightness [PercentType, Numeric] Brightness component (0-100%)
49
49
  # @return [HSBType]
50
- def from_hsv(hue, saturation, brightness)
50
+ def from_hsb(hue, saturation, brightness)
51
51
  new(hue, saturation, brightness)
52
52
  end
53
53
 
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.21.0'
8
+ VERSION = '4.23.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: 4.21.0
4
+ version: 4.23.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-12-02 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler