openhab-scripting 4.38.0 → 4.39.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: 249167484484abf9fb6c7128e5e697fd4e1d767576ad52b22005ee473d52776e
4
- data.tar.gz: 6825c83f1cdd668882c3409c0cc828c69e259e553ba736eb9291a0ec1370c57d
3
+ metadata.gz: 1fb1294914e9c3e343bef8f0c1aaca327dbaa5875d446ec3e507edc1f390c9c9
4
+ data.tar.gz: be121541f849f733505c6180557f88fdd98869d89e0a593c6fc48db0e7e6daf5
5
5
  SHA512:
6
- metadata.gz: 7d8c8f1f4aab62fecedbe0b8e6693f263e3a21c2ddbb188e5f16cffaf59643d1ffc27c71bb1c14cd256f1852ab6187890c4289791d862ef8e6dcfb1e8f06d096
7
- data.tar.gz: ed683ceab7adbcdfb6882409f8c52fac4e06b15c23662f108488cc192594f21d13d1614b4e645f9c00dec94739321d931fa2c7cfcb1c78ebc6157882c0cdaff3
6
+ metadata.gz: e6af3e7152dd02c9d98dea19f9bcaa4f474a20daac090941c1121705d177afec2498a2704462645d51b6e4e055efda1f0431702c0f7c6f126718b7994ef6baad
7
+ data.tar.gz: f9af8246710e44dc86719d10ba2577003293640e1c11885c054da9d23d0be8746e1103151c173672ddfab96ae218f5d717318ab72d628a194f7a243647ea885d
@@ -99,7 +99,6 @@ module OpenHAB
99
99
  module Items
100
100
  GenericItem.prepend(OpenHAB::DSL::Ensure::GenericItem)
101
101
  GroupItem::GroupMembers.include(OpenHAB::DSL::Ensure::Ensurable)
102
- Enumerable.include(OpenHAB::DSL::Ensure::Ensurable)
103
102
  end
104
103
  end
105
104
  end
@@ -32,6 +32,11 @@ module Enumerable
32
32
  each { |i| i.update(state) }
33
33
  end
34
34
 
35
+ # Returns the group members the elements
36
+ def members
37
+ select { |e| e.respond_to? :members }.flat_map(&:members)
38
+ end
39
+
35
40
  # @!method refresh
36
41
  # Send the +REFRESH+ command to every item in the collection
37
42
 
@@ -76,4 +81,11 @@ module Enumerable
76
81
 
77
82
  # @!method previous
78
83
  # Send the +PREVIOUS+ command to every item in the collection
84
+
85
+ # @!visibility private
86
+ # can't use `include`, because Enumerable has already been included
87
+ # in other classes
88
+ def ensure
89
+ OpenHAB::DSL::Ensure::GenericItemDelegate.new(self)
90
+ end
79
91
  end
@@ -148,8 +148,8 @@ module OpenHAB
148
148
  # @example Search a Thermostat item for is setpoints
149
149
  # eFamilyThermostat.points(Semantics::Control, Semantics::Temperature)
150
150
  # # => [FamilyThermostat_HeatingSetpoint, FamilyThermostat_CoolingSetpoint]
151
- # @example Given a A/V receiver's input item, search for it's power item
152
- # FamilyReceiver_Input.points(Semantics::Switch) # => FamilyReceiver_Switch
151
+ # @example Given a A/V receiver's input item, search for its power item
152
+ # FamilyReceiver_Input.points(Semantics::Switch) # => [FamilyReceiver_Switch]
153
153
  #
154
154
  # @param [Class] point_or_property_types
155
155
  # Pass 1 or 2 classes that are sub-classes of [Point] or [Property].
@@ -199,7 +199,7 @@ module Enumerable
199
199
  # Returns a new array of items that are semantics points (optionally of a given type)
200
200
  #
201
201
  # @example Get all the power switch items for every equipment in a room
202
- # lGreatRoom.equipments.flat_map(&:members).points(Semantics::Switch)
202
+ # lGreatRoom.equipments.points(Semantics::Switch)
203
203
  def points(*point_or_property_types) # rubocop:disable Metrics
204
204
  unless (0..2).cover?(point_or_property_types.length)
205
205
  raise ArgumentError, "wrong number of arguments (given #{point_or_property_types.length}, expected 0..2)"
@@ -214,13 +214,27 @@ module Enumerable
214
214
  raise ArgumentError, 'point_or_property_types cannot both be a subclass of Point or Property'
215
215
  end
216
216
 
217
- select do |point|
218
- next unless point.point?
219
-
217
+ filter_with_members(&:point?)
218
+ .select do |point|
220
219
  point_or_property_types.all? do |tag|
221
220
  (tag < OpenHAB::DSL::Semantics::Point && point.point_type&.<=(tag)) ||
222
221
  (tag < OpenHAB::DSL::Semantics::Property && point.property_type&.<=(tag))
223
222
  end
224
223
  end
225
224
  end
225
+
226
+ #
227
+ # Select the elements where the given block returns true.
228
+ # If the block returns false but the element is a GroupItem with members,
229
+ # merge its members into the result and filter them using the same block
230
+ #
231
+ # @param [Block] &block A block that returns true for the elements and members to be included in the result
232
+ #
233
+ # @return [Array] The resulting array
234
+ #
235
+ # !@visibility private
236
+ def filter_with_members(&block)
237
+ selected, others = partition(&block)
238
+ others.members.select(&block).concat(selected)
239
+ end
226
240
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.38.0'
8
+ VERSION = '4.39.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.38.0
4
+ version: 4.39.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: 2022-04-15 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler