openhab-scripting 5.0.1 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/items/generic_item.rb +4 -2
- data/lib/openhab/core/items/semantics.rb +177 -10
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +4 -4
- data/lib/openhab/rspec/mocks/persistence_service.rb +1 -1
- data/lib/openhab/yard/markdown_helper.rb +3 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17db43cc91f70e705ab8002d2653afe72cad963ad92907d9535ee906082cca97
|
4
|
+
data.tar.gz: 0cf4c4c56fbf427fbf37a47571b20294176b29a89140428cb2b6f29c495c5a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a20f62e3c416f1801d92216a64495737cacb017257644506040c8412908ffa15575356707c947757160b9d03ff340a6c8abeab25924bdca2f79979f63b0a148
|
7
|
+
data.tar.gz: ce9de9508194ae985223f92457184bb1c42af089605171950d13cdbf93d132a1955dcd8d9773a9749272ec13a3c956d4b0788e1cc632e50900204568c0276181
|
@@ -77,7 +77,7 @@ module OpenHAB
|
|
77
77
|
#
|
78
78
|
# This may include running a transformation.
|
79
79
|
#
|
80
|
-
# @return [String]
|
80
|
+
# @return [String] The formatted state
|
81
81
|
#
|
82
82
|
# @example
|
83
83
|
# logger.info(Exterior_WindDirection.formatted_state) # => "NE (36°)"
|
@@ -92,7 +92,9 @@ module OpenHAB
|
|
92
92
|
transformed_state_string = org.openhab.core.transform.TransformationHelper.transform(OSGi.bundle_context,
|
93
93
|
pattern,
|
94
94
|
raw_state_string)
|
95
|
-
|
95
|
+
if transformed_state_string.nil? || transformed_state_string == raw_state_string
|
96
|
+
return state&.format(pattern) || raw_state_string
|
97
|
+
end
|
96
98
|
|
97
99
|
transformed_state_string
|
98
100
|
rescue org.openhab.core.transform.TransformationException
|
@@ -60,6 +60,12 @@ module OpenHAB
|
|
60
60
|
# and {#property_type}. They can even be used with
|
61
61
|
# {DSL::Items::ItemBuilder#tag}.
|
62
62
|
#
|
63
|
+
# The semantic constants in the `Semantics` module are enhanced with {TagClassMethods}
|
64
|
+
# to provide easy access to the tags' additional attributes: {TagClassMethods.label label},
|
65
|
+
# {TagClassMethods.synonyms synonyms}, and {TagClassMethods.description description}.
|
66
|
+
# For example, to get the synonyms for `Semantics::Lightbulb` in German:
|
67
|
+
# `Semantics::Lightbulb.synonyms(java.util.Locale::GERMAN)`
|
68
|
+
#
|
63
69
|
# @see https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.semantics/model/SemanticTags.csv Semantic Tags Table
|
64
70
|
#
|
65
71
|
# @example Working with tags
|
@@ -156,6 +162,12 @@ module OpenHAB
|
|
156
162
|
# # All items tagged "SmartLightControl"
|
157
163
|
# items.tagged("SmartLightControl")
|
158
164
|
#
|
165
|
+
# ## Adding Custom Semantic Tags
|
166
|
+
#
|
167
|
+
# openHAB 4 supports adding custom semantic tags to augment the standard set of tags to better suit
|
168
|
+
# your particular requirements.
|
169
|
+
#
|
170
|
+
# For more information, see {add}
|
159
171
|
#
|
160
172
|
module Semantics
|
161
173
|
GenericItem.include(self)
|
@@ -188,15 +200,6 @@ module OpenHAB
|
|
188
200
|
# end
|
189
201
|
#
|
190
202
|
|
191
|
-
# import all the semantics constants
|
192
|
-
[org.openhab.core.semantics.model.point.Points,
|
193
|
-
org.openhab.core.semantics.model.property.Properties,
|
194
|
-
org.openhab.core.semantics.model.equipment.Equipments,
|
195
|
-
org.openhab.core.semantics.model.location.Locations].each do |parent_tag|
|
196
|
-
parent_tag.stream.for_each do |tag|
|
197
|
-
const_set(tag.simple_name.to_sym, tag.ruby_class)
|
198
|
-
end
|
199
|
-
end
|
200
203
|
# This is a marker interface for all semantic tag classes.
|
201
204
|
# @interface
|
202
205
|
Tag = org.openhab.core.semantics.Tag
|
@@ -390,6 +393,169 @@ module OpenHAB
|
|
390
393
|
result.delete(self)
|
391
394
|
result
|
392
395
|
end
|
396
|
+
|
397
|
+
# @deprecated OH3.4 - this check is only needed for OH3.4
|
398
|
+
if org.openhab.core.semantics.SemanticTags.respond_to?(:add)
|
399
|
+
|
400
|
+
#
|
401
|
+
# Adds custom semantic tags.
|
402
|
+
#
|
403
|
+
# @return [Array<Tag>] An array of tags successfully added.
|
404
|
+
#
|
405
|
+
# @overload self.add(**tags)
|
406
|
+
# Quickly add one or more semantic tags using the default label, empty synonyms and descriptions.
|
407
|
+
#
|
408
|
+
# @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a Symbol or a String
|
409
|
+
# for the tag to be added, and parent is either a {Tag}, a symbol or a string of an existing tag.
|
410
|
+
# @return [Array<Tag>] An array of tags successfully added.
|
411
|
+
#
|
412
|
+
# @example Add one semantic tag `Balcony` whose parent is `Semantics::Outdoor` (Location)
|
413
|
+
# Semantics.add(Balcony: Semantics::Outdoor)
|
414
|
+
#
|
415
|
+
# @example Add multiple semantic tags
|
416
|
+
# Semantics.add(Balcony: Semantics::Outdoor,
|
417
|
+
# SecretRoom: Semantics::Room,
|
418
|
+
# Motion: Semantics::Property)
|
419
|
+
#
|
420
|
+
# @overload self.add(label: nil, synonyms: "", description: "", **tags)
|
421
|
+
# Add a custom semantic tag with extra details.
|
422
|
+
#
|
423
|
+
# @example
|
424
|
+
# Semantics.add(SecretRoom: Semantics::Room, label: "My Secret Room",
|
425
|
+
# synonyms: "HidingPlace", description: "A room that requires a special trick to enter")
|
426
|
+
#
|
427
|
+
# @param [String,nil] label Optional label. When nil, infer the label from the tag name,
|
428
|
+
# converting `CamelCase` to `Camel Case`
|
429
|
+
# @param [String,Array<String,Symbol>] synonyms An array of synonyms, or a string containing a
|
430
|
+
# comma separated list of synonyms for this tag.
|
431
|
+
# @param [String] description A longer description of the tag.
|
432
|
+
# @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a Symbol or a String
|
433
|
+
# for the tag to be added, and parent is either a {Tag}, a symbol or a string of an existing tag.
|
434
|
+
# @return [Array<Tag>] An array of tags successfully added.
|
435
|
+
#
|
436
|
+
def self.add(label: nil, synonyms: "", description: "", **tags)
|
437
|
+
raise "Tags must be specified" if tags.empty?
|
438
|
+
if (tags.length > 1) && !(label.nil? && synonyms.empty? && description.empty?)
|
439
|
+
raise "Additional options can only be specified when creating one tag"
|
440
|
+
end
|
441
|
+
|
442
|
+
synonyms = synonyms.map(&:to_s).map(&:strip).join(",") if synonyms.is_a?(Array)
|
443
|
+
|
444
|
+
tags.map do |name, parent|
|
445
|
+
parent_is_tag = parent.respond_to?(:java_class) && parent.java_class < Tag.java_class
|
446
|
+
parent = parent_is_tag ? parent.java_class : parent.to_s
|
447
|
+
name = name.to_s
|
448
|
+
org.openhab.core.semantics.SemanticTags.add(name, parent, label, synonyms, description)
|
449
|
+
&.then { const_missing(name) }
|
450
|
+
end.compact
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
#
|
455
|
+
# Returns all available Semantic tags
|
456
|
+
#
|
457
|
+
# @return [Array<Tag>] an array containing all the Semantic tags
|
458
|
+
#
|
459
|
+
def self.tags
|
460
|
+
java.util.stream.Stream.of(
|
461
|
+
org.openhab.core.semantics.model.point.Points.stream,
|
462
|
+
org.openhab.core.semantics.model.property.Properties.stream,
|
463
|
+
org.openhab.core.semantics.model.equipment.Equipments.stream,
|
464
|
+
org.openhab.core.semantics.model.location.Locations.stream
|
465
|
+
).flat_map(&:itself).map(&:ruby_class).iterator.to_a
|
466
|
+
end
|
467
|
+
|
468
|
+
#
|
469
|
+
# Finds the semantic tag using its name, label, or synonyms.
|
470
|
+
#
|
471
|
+
# @param [String,Symbol] id The tag name, label, or synonym to look up
|
472
|
+
# @param [java.util.Locale] locale The locale of the given label or synonym
|
473
|
+
#
|
474
|
+
# @return [Tag,nil] The semantic tag class if found, or nil if not found.
|
475
|
+
#
|
476
|
+
def self.lookup(id, locale = nil)
|
477
|
+
id = id.to_sym
|
478
|
+
return const_get(id) if constants.include?(id) || const_missing(id)
|
479
|
+
|
480
|
+
locale = java.util.Locale.default if locale.nil?
|
481
|
+
org.openhab.core.semantics.SemanticTags.get_by_label_or_synonym(id.to_s, locale).first&.ruby_class
|
482
|
+
end
|
483
|
+
|
484
|
+
#
|
485
|
+
# Automatically looks up new semantic classes and adds them as `constants`
|
486
|
+
#
|
487
|
+
# @return [Tag, nil]
|
488
|
+
#
|
489
|
+
# @!visibility private
|
490
|
+
def self.const_missing(sym)
|
491
|
+
logger.trace("const missing, performing Semantics Lookup for: #{sym}")
|
492
|
+
# @deprecated OH3.4 - the Property tag had an ID of "MeasurementProperty" in OH3.4. This was corrected in OH4.
|
493
|
+
# make sure we compare against pre-release versions
|
494
|
+
target_sym = sym
|
495
|
+
if sym == :Property && Gem::Version.new(Core::VERSION) < Gem::Version.new("4.0.0.M1")
|
496
|
+
sym = :MeasurementProperty
|
497
|
+
end
|
498
|
+
|
499
|
+
org.openhab.core.semantics.SemanticTags.get_by_id(sym.to_s)
|
500
|
+
&.then do |tag|
|
501
|
+
tag = tag.ruby_class
|
502
|
+
tag.singleton_class.include(TagClassMethods)
|
503
|
+
const_set(target_sym, tag)
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
#
|
508
|
+
# Adds tag attributes to the semantic tag class
|
509
|
+
#
|
510
|
+
module TagClassMethods
|
511
|
+
# @!visibility private
|
512
|
+
java_import org.openhab.core.semantics.SemanticTags
|
513
|
+
|
514
|
+
#
|
515
|
+
# Returns the tag's label
|
516
|
+
#
|
517
|
+
# @param [java.util.Locale] locale The locale that the label should be in, if available.
|
518
|
+
# When nil, the system's default locale is used.
|
519
|
+
#
|
520
|
+
# @return [String] The tag's label
|
521
|
+
#
|
522
|
+
def label(locale = nil)
|
523
|
+
SemanticTags.get_label(java_class, locale || java.util.Locale.default)
|
524
|
+
end
|
525
|
+
|
526
|
+
#
|
527
|
+
# Returns the tag's synonyms
|
528
|
+
#
|
529
|
+
# @param [java.util.Locale] locale The locale that the label should be in, if available.
|
530
|
+
# When nil, the system's default locale is used.
|
531
|
+
#
|
532
|
+
# @return [Array<String>] The list of synonyms in the requested locale.
|
533
|
+
#
|
534
|
+
def synonyms(locale = nil)
|
535
|
+
unless SemanticTags.respond_to?(:get_synonyms) # @deprecated OH3.4
|
536
|
+
return java_class.get_annotation(org.openhab.core.semantics.TagInfo.java_class).synonyms
|
537
|
+
.split(",").map(&:strip)
|
538
|
+
end
|
539
|
+
|
540
|
+
SemanticTags.get_synonyms(java_class, locale || java.util.Locale.default).to_a
|
541
|
+
end
|
542
|
+
|
543
|
+
#
|
544
|
+
# Returns the tag's description
|
545
|
+
#
|
546
|
+
# @param [java.util.Locale] locale The locale that the description should be in, if available.
|
547
|
+
# When nil, the system's default locale is used.
|
548
|
+
#
|
549
|
+
# @return [String] The tag's description
|
550
|
+
#
|
551
|
+
def description(locale = nil)
|
552
|
+
unless SemanticTags.respond_to?(:get_description) # @deprecated OH3.4
|
553
|
+
return java_class.get_annotation(org.openhab.core.semantics.TagInfo.java_class).description
|
554
|
+
end
|
555
|
+
|
556
|
+
SemanticTags.get_description(java_class, locale || java.util.Locale.default)
|
557
|
+
end
|
558
|
+
end
|
393
559
|
end
|
394
560
|
end
|
395
561
|
end
|
@@ -454,7 +620,8 @@ module Enumerable
|
|
454
620
|
end
|
455
621
|
unless point_or_property_types.all? do |tag|
|
456
622
|
tag.is_a?(Module) &&
|
457
|
-
(tag < Semantics::Point ||
|
623
|
+
(tag < Semantics::Point ||
|
624
|
+
tag < Semantics::Property)
|
458
625
|
end
|
459
626
|
raise ArgumentError, "point_or_property_types must all be a subclass of Point or Property"
|
460
627
|
end
|
data/lib/openhab/dsl/version.rb
CHANGED
data/lib/openhab/dsl.rb
CHANGED
@@ -127,7 +127,7 @@ module OpenHAB
|
|
127
127
|
# # strip the unit from the command, as the binding likely can't handle it
|
128
128
|
# next true unless command.is_a?(QuantityType)
|
129
129
|
#
|
130
|
-
# callback.
|
130
|
+
# callback.handle_command(DecimalType.new(command.to_d))
|
131
131
|
# false
|
132
132
|
# else
|
133
133
|
# true # pass other events through as normal
|
@@ -777,7 +777,7 @@ module OpenHAB
|
|
777
777
|
# Sets the implicit provider(s) for operations inside the block.
|
778
778
|
#
|
779
779
|
# @param (see #provider!)
|
780
|
-
# @yield [] The block will be executed
|
780
|
+
# @yield [] The block will be executed using the specified provider(s).
|
781
781
|
# @return [Object] the result of the block
|
782
782
|
#
|
783
783
|
# @example
|
@@ -793,11 +793,11 @@ module OpenHAB
|
|
793
793
|
# @see provider!
|
794
794
|
# @see OpenHAB::Core::Provider.current Provider.current for how the current provider is calculated
|
795
795
|
#
|
796
|
-
def provider(*
|
796
|
+
def provider(*providers, **providers_by_type)
|
797
797
|
raise ArgumentError, "You must give a block to set the provider for the duration of" unless block_given?
|
798
798
|
|
799
799
|
begin
|
800
|
-
old_providers = provider!(*
|
800
|
+
old_providers = provider!(*providers, **providers_by_type)
|
801
801
|
yield
|
802
802
|
ensure
|
803
803
|
Thread.current[:openhab_providers] = old_providers
|
@@ -52,6 +52,9 @@ module OpenHAB
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
# Remove the "omit from toc" comments
|
56
|
+
result.gsub!(" <!-- omit from toc -->", "")
|
57
|
+
|
55
58
|
# re-link files in docs/*.md. They're written so they work on github without any
|
56
59
|
# processing
|
57
60
|
result.gsub!(%r{\[([A-Za-z0-9,. ]+)\]\(([A-Za-z0-9./-]+)\)}) do |str|
|
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.1.1
|
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-04-
|
13
|
+
date: 2023-04-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '1.2'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: faraday-retry
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '2.1'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '2.1'
|
99
113
|
- !ruby/object:Gem::Dependency
|
100
114
|
name: gem-release
|
101
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +124,20 @@ dependencies:
|
|
110
124
|
- - "~>"
|
111
125
|
- !ruby/object:Gem::Version
|
112
126
|
version: '2.2'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: github_changelog_generator
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.16'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '1.16'
|
113
141
|
- !ruby/object:Gem::Dependency
|
114
142
|
name: guard-rubocop
|
115
143
|
requirement: !ruby/object:Gem::Requirement
|