openhab-scripting 4.15.1 → 4.16.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: 9fa69c603c1f7a32428d12860585b0a4059c70b617b6df72d3da0521a7e36163
4
- data.tar.gz: 68527c0ea3b42ba5187322062dbe05d4a22bef29dabd048af9336ff80e7da5b7
3
+ metadata.gz: f765fc75455c9aace6d355e897477c727dcdc7e826bb3b16824979c2cf882f56
4
+ data.tar.gz: cfb0262989931a22e637e1e2f625ca3f5256da37587d8400b10f68ece4b6c358
5
5
  SHA512:
6
- metadata.gz: 7115395f5f02afcbd5b2e3cb243192aaed694309d24383005c567859bba6cf693286c772edb101ce924d10268bc986f406d2ee8dc1a7f942be07793b91dc1ca8
7
- data.tar.gz: 9d9a0478ba8ee6275014ddbdc03fe67ed23a15acef1813d5195109dbc9069ca2b3d69d5a038a7bf3a4c22ec52433144659e46bf3481c3e5055b97ff8d7920f1e
6
+ metadata.gz: 99b0f1896dd66a599449dd96b061f38cc6ad92694bd9502bf14b5b6767330d8eebd714ea41536bb49f730a6fdb9c48e64a04b77c7cb9d54e72d61d617336c2d9
7
+ data.tar.gz: ff13507c8f80c3f7dbae3089d8ef322e0c0fbaccf835cdb80ea58ea4e595ac8e92b2e440cf4a2c8c2bf9c9401f9da7f98219857ed88ead80adbe853f3b2f2b76
@@ -131,6 +131,25 @@ module OpenHAB
131
131
  group_names.map { |name| Groups.groups[name] }
132
132
  end
133
133
 
134
+ # Return the item's thing if this item is linked with a thing. If an item is linked to more than one thing,
135
+ # this method only returns the first thing.
136
+ #
137
+ # @return [Thing] The thing associated with this item or nil
138
+ def thing
139
+ all_linked_things.first
140
+ end
141
+ alias linked_thing thing
142
+
143
+ # Returns all of the item's linked things.
144
+ #
145
+ # @return [Array] An array of things or an empty array
146
+ def things
147
+ registry = OpenHAB::Core::OSGI.service('org.openhab.core.thing.link.ItemChannelLinkRegistry')
148
+ channels = registry.get_bound_channels(name).to_a
149
+ channels.map(&:thing_uid).uniq.map { |tuid| Object.things[tuid] }
150
+ end
151
+ alias all_linked_things things
152
+
134
153
  #
135
154
  # Check equality without type conversion
136
155
  #
@@ -83,11 +83,11 @@ module OpenHAB
83
83
  include LazyArray
84
84
  include Singleton
85
85
 
86
- # Gets a specific thing by name in the format binding_id:type_id:thing_id
87
- # @return Thing specified by name or nil if name does not exist in thing registry
86
+ # Gets a specific thing by name in the format binding_id:type_id:thing_id or via the ThingUID
87
+ # @return Thing specified by name/UID or nil if name/UID does not exist in thing registry
88
88
  def [](uid)
89
- thing_uid = org.openhab.core.thing.ThingUID.new(*uid.split(':'))
90
- thing = $things.get(thing_uid) # rubocop: disable Style/GlobalVars
89
+ uid = generate_thing_uid(uid) unless uid.is_a?(org.openhab.core.thing.ThingUID)
90
+ thing = $things.get(uid) # rubocop: disable Style/GlobalVars
91
91
  return unless thing
92
92
 
93
93
  logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
@@ -100,6 +100,15 @@ module OpenHAB
100
100
  def to_a
101
101
  $things.getAll.map { |thing| Thing.new(thing) } # rubocop: disable Style/GlobalVars
102
102
  end
103
+
104
+ private
105
+
106
+ # Returns a ThingUID given a string like object
107
+ #
108
+ # @return ThingUID generated by given name
109
+ def generate_thing_uid(uid)
110
+ org.openhab.core.thing.ThingUID.new(*uid.split(':'))
111
+ end
103
112
  end
104
113
 
105
114
  #
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.15.1'
8
+ VERSION = '4.16.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.15.1
4
+ version: 4.16.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-11-24 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler