openhab-scripting 5.2.0 → 5.3.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 +4 -4
- data/lib/openhab/core_ext/ruby/object.rb +30 -0
- data/lib/openhab/dsl/items/builder.rb +68 -3
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a914cbf39d73f385d8f250fb88a72737cabec9106871009f0b4679176251680a
|
4
|
+
data.tar.gz: 402616a86763701e48146d24581c340287c060bb8e86fb28e9c2e1947e19b129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a860c8a2969e3a10b513650f265a3291f1cc5b91fa0b9d1775f40e254904175fe6e077881cb24ebef13677085705c3ae2248420064154da61a7ced4af4a91c67
|
7
|
+
data.tar.gz: 13e3da787706aee119334f4e768a9af3d2eaefc38afb8b2e6618e74e6591bc8cfcfa7ff137fa514d2bed2831e416f6112d8a27b7a6a8a205fdf8eefdbaafff31
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module CoreExt
|
5
|
+
module Ruby
|
6
|
+
# @!visibility private
|
7
|
+
module Object
|
8
|
+
class << self
|
9
|
+
attr_reader :top_self
|
10
|
+
end
|
11
|
+
|
12
|
+
# @!visibility private
|
13
|
+
module ClassMethods
|
14
|
+
# capture methods defined at top level (which get added to Object)
|
15
|
+
def method_added(method)
|
16
|
+
return super unless equal?(::Object)
|
17
|
+
|
18
|
+
if DSL.private_instance_methods.include?(method)
|
19
|
+
# Duplicate methods that conflict with DSL onto `main`'s singleton class,
|
20
|
+
# so that they'll take precedence over DSL's method.
|
21
|
+
Object.top_self.singleton_class.define_method(method, instance_method(method))
|
22
|
+
end
|
23
|
+
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -22,6 +22,12 @@ module OpenHAB
|
|
22
22
|
# group_item Equipment, tags: Semantics::HVAC, thing: "binding:thing"
|
23
23
|
# string_item Mode, tags: Semantics::Control, channel: "mode"
|
24
24
|
# end
|
25
|
+
#
|
26
|
+
# # dimension Temperature inferred
|
27
|
+
# number_item OutdoorTemp, format: "%.1f %unit%", unit: "°F"
|
28
|
+
#
|
29
|
+
# # unit lx, dimension Illuminance, format "%s %unit%" inferred
|
30
|
+
# number_item OutdoorBrightness, state: 10_000 | "lx"
|
25
31
|
# end
|
26
32
|
#
|
27
33
|
module Builder
|
@@ -156,9 +162,22 @@ module OpenHAB
|
|
156
162
|
# @return [String, nil]
|
157
163
|
attr_accessor :label
|
158
164
|
# Unit dimension (for number items only)
|
165
|
+
#
|
166
|
+
# If {unit} is provided, and {dimension} is not, it will be inferred.
|
167
|
+
#
|
159
168
|
# @return [String, nil]
|
160
169
|
attr_accessor :dimension
|
170
|
+
# Unit (for number items only)
|
171
|
+
#
|
172
|
+
# Due to {format} inference, setting the unit is cross-compatible with
|
173
|
+
# openHAB 3.4 and 4.0.
|
174
|
+
#
|
175
|
+
# @return [String, nil]
|
176
|
+
attr_reader :unit
|
161
177
|
# The formatting pattern for the item's state
|
178
|
+
#
|
179
|
+
# If {unit} is provided, and {format} is not, it will be inferred.
|
180
|
+
#
|
162
181
|
# @return [String, nil]
|
163
182
|
attr_accessor :format
|
164
183
|
# The icon to be associated with the item
|
@@ -179,13 +198,16 @@ module OpenHAB
|
|
179
198
|
# @return [Core::Items::Metadata::NamespaceHash]
|
180
199
|
attr_reader :metadata
|
181
200
|
# Initial state
|
201
|
+
#
|
202
|
+
# If {state} is set to a {QuantityType}, and {unit} is not set, it will be inferred.
|
203
|
+
#
|
182
204
|
# @return [Core::Types::State]
|
183
|
-
|
205
|
+
attr_reader :state
|
184
206
|
|
185
207
|
class << self
|
186
208
|
# @!visibility private
|
187
209
|
def item_factory
|
188
|
-
@item_factory ||= org.openhab.core.
|
210
|
+
@item_factory ||= OpenHAB::OSGi.service("org.openhab.core.items.ItemFactory")
|
189
211
|
end
|
190
212
|
|
191
213
|
#
|
@@ -214,6 +236,7 @@ module OpenHAB
|
|
214
236
|
end
|
215
237
|
|
216
238
|
# @param dimension [Symbol, nil] The unit dimension for a {NumberItem} (see {ItemBuilder#dimension})
|
239
|
+
# @param unit [Symbol, String, nil] The unit for a {NumberItem} (see {ItemBuilder#unit})
|
217
240
|
# @param format [String, nil] The formatting pattern for the item's state (see {ItemBuilder#format})
|
218
241
|
# @param icon [Symbol, nil] The icon to be associated with the item (see {ItemBuilder#icon})
|
219
242
|
# @param group [String,
|
@@ -246,6 +269,7 @@ module OpenHAB
|
|
246
269
|
def initialize(type, name = nil, label = nil,
|
247
270
|
provider:,
|
248
271
|
dimension: nil,
|
272
|
+
unit: nil,
|
249
273
|
format: nil,
|
250
274
|
icon: nil,
|
251
275
|
group: nil,
|
@@ -274,6 +298,7 @@ module OpenHAB
|
|
274
298
|
@label = label
|
275
299
|
@dimension = dimension
|
276
300
|
@format = format
|
301
|
+
self.unit = unit
|
277
302
|
@icon = icon
|
278
303
|
@groups = []
|
279
304
|
@tags = []
|
@@ -291,7 +316,7 @@ module OpenHAB
|
|
291
316
|
self.alexa(alexa) if alexa
|
292
317
|
self.ga(ga) if ga
|
293
318
|
self.homekit(homekit) if homekit
|
294
|
-
|
319
|
+
self.state = state
|
295
320
|
|
296
321
|
self.group(*group)
|
297
322
|
self.group(*groups)
|
@@ -434,6 +459,39 @@ module OpenHAB
|
|
434
459
|
@expire += ",command=#{command}" if command
|
435
460
|
end
|
436
461
|
|
462
|
+
# @!attribute [w] unit
|
463
|
+
#
|
464
|
+
# Unit (for number items only).
|
465
|
+
#
|
466
|
+
# If dimension or format are not yet set, they will be inferred.
|
467
|
+
#
|
468
|
+
# @return [String, nil]
|
469
|
+
def unit=(unit)
|
470
|
+
@unit = unit
|
471
|
+
|
472
|
+
self.dimension ||= unit && org.openhab.core.types.util.UnitUtils.parse_unit(unit)&.then do |u|
|
473
|
+
org.openhab.core.types.util.UnitUtils.get_dimension_name(u)
|
474
|
+
end
|
475
|
+
self.format ||= unit && (if Gem::Version.new(Core::VERSION) >= Gem::Version.new("4.0.0.M3")
|
476
|
+
"%s %unit%"
|
477
|
+
else
|
478
|
+
"%s #{unit.gsub("%", "%%")}"
|
479
|
+
end)
|
480
|
+
end
|
481
|
+
|
482
|
+
# @!attribute [w] state
|
483
|
+
#
|
484
|
+
# Initial state
|
485
|
+
#
|
486
|
+
# If {state} is set to a {QuantityType}, and {unit} is not set, it will be inferred.
|
487
|
+
#
|
488
|
+
# @return [Core::Types::State]
|
489
|
+
def state=(state)
|
490
|
+
@state = state
|
491
|
+
|
492
|
+
self.unit ||= state.unit.to_s if state.is_a?(QuantityType)
|
493
|
+
end
|
494
|
+
|
437
495
|
# @!visibility private
|
438
496
|
def build
|
439
497
|
item = create_item
|
@@ -450,6 +508,7 @@ module OpenHAB
|
|
450
508
|
item.metadata["autoupdate"] = autoupdate.to_s unless autoupdate.nil?
|
451
509
|
item.metadata["expire"] = expire if expire
|
452
510
|
item.metadata["stateDescription"] = { "pattern" => format } if format
|
511
|
+
item.metadata["unit"] = unit if unit
|
453
512
|
item.state = item.format_update(state) unless state.nil?
|
454
513
|
item
|
455
514
|
end
|
@@ -488,6 +547,12 @@ module OpenHAB
|
|
488
547
|
class GroupItemBuilder < ItemBuilder
|
489
548
|
include Builder
|
490
549
|
|
550
|
+
# This has to be duplicated here, since {Builder} includes DSL, so DSL#unit
|
551
|
+
# will be seen first, but we really want ItemBuilder#unit
|
552
|
+
|
553
|
+
# (see ItemBuilder#unit)
|
554
|
+
attr_reader :unit
|
555
|
+
|
491
556
|
Builder.public_instance_methods.each do |m|
|
492
557
|
next unless Builder.instance_method(m).owner == Builder
|
493
558
|
|
data/lib/openhab/dsl/version.rb
CHANGED
data/lib/openhab/dsl.rb
CHANGED
@@ -975,5 +975,8 @@ OpenHAB::Core::Items.import_into_global_namespace
|
|
975
975
|
|
976
976
|
# Extend `main` with DSL methods
|
977
977
|
singleton_class.include(OpenHAB::DSL)
|
978
|
+
# Patch Object to work around https://github.com/openhab/openhab-jruby/issues/4
|
979
|
+
Object.extend(OpenHAB::CoreExt::Ruby::Object::ClassMethods)
|
980
|
+
OpenHAB::CoreExt::Ruby::Object.instance_variable_set(:@top_self, self)
|
978
981
|
|
979
982
|
logger.debug "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded"
|
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: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-05-
|
13
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -504,6 +504,7 @@ files:
|
|
504
504
|
- lib/openhab/core_ext/ruby/date_time.rb
|
505
505
|
- lib/openhab/core_ext/ruby/module.rb
|
506
506
|
- lib/openhab/core_ext/ruby/numeric.rb
|
507
|
+
- lib/openhab/core_ext/ruby/object.rb
|
507
508
|
- lib/openhab/core_ext/ruby/range.rb
|
508
509
|
- lib/openhab/core_ext/ruby/symbol.rb
|
509
510
|
- lib/openhab/core_ext/ruby/time.rb
|