openhab-scripting 4.18.0 → 4.19.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: 775d56e757a494c9b854b963f2c15393c2521597cd83e5d36452a41033508339
4
- data.tar.gz: 9dfd101285ad28b310156016e524a370352b192147f3fbf87d130135b5a48b9d
3
+ metadata.gz: 7a1c3efdcd1a6b1b37802084ae9905afca8ea737cf870e1d51c0df7fabafd7f2
4
+ data.tar.gz: 3bf072ccd50f0271a2633d174e95e8fd4de112f669ba40e0c5f325be6b30946f
5
5
  SHA512:
6
- metadata.gz: 773d6bc398e5b24a9aecfb265c6025c75c4863ddf80932e875e9cb60eea4e6fdbf8036803d17c25dfd429127fc5164f1264b4bc48f7fce2cee1cd3fde837372a
7
- data.tar.gz: 2e19d2dd05b40da151bd85a253e022209c93819acd20872bd1a30f02d9ad96cdb931c81499f7c222c2c487f962cb56f9db851dee6e3c038a671bac4d44f5481d
6
+ metadata.gz: 9f3d963c6d2bc0b148dc122ec3483e301a04ee70c3f3cdf9b04a98b289f4dd823f1192344767aed9712d2745f01be7a51e62043d76a652dbdafd63ff7a98d065
7
+ data.tar.gz: d6a98e072d3462a1d74fd9d968c8a3eeeb66f7df747aee054640b6d2f9ca76358dc7e10bc93a2106b60bc508778f83ef649dfd2e3153f6d6c2e43590cfeeed53
@@ -19,6 +19,7 @@ require 'openhab/dsl/things'
19
19
  require 'openhab/dsl/between'
20
20
  require 'openhab/dsl/gems'
21
21
  require 'openhab/dsl/persistence'
22
+ require 'openhab/dsl/uid'
22
23
  require 'openhab/dsl/units'
23
24
  require 'openhab/dsl/states'
24
25
 
@@ -15,16 +15,19 @@ module OpenHAB
15
15
  #
16
16
  # Creates a channel trigger
17
17
  #
18
- # @param [Array] channels array to create triggers for on form of 'binding_id:type_id:thing_id#channel_id'
18
+ # @param [String, Channel, ChannelUID, Array<String, Channel, ChannelUID>] channels
19
+ # channels to create triggers for in form of 'binding_id:type_id:thing_id#channel_id'
19
20
  # or 'channel_id' if thing is provided
20
- # @param [thing] thing to create trigger for if not specified with the channel
21
- # @param [String] triggered specific triggering condition to match for trigger
22
- #
23
- #
24
- def channel(*channels, thing: nil, triggered: nil, attach: nil)
25
- channels.flatten.each do |channel|
26
- channel = [thing, channel].join(':') if thing
27
- logger.trace("Creating channel trigger for channel(#{channel}), thing(#{thing}), trigger(#{triggered})")
21
+ # @param [String, Thing, ThingUID, Array<String, Thing, ThingUID>] thing
22
+ # thing(s) to create trigger for if not specified with the channel
23
+ # @param [String, Array<String>] triggered specific triggering condition(s) to match for trigger
24
+ #
25
+ def channel(*channels, thing: nil, triggered: nil, attach: nil) # rubocop:disable Metrics/AbcSize
26
+ channels.flatten.product([thing].flatten).each do |(channel, t)|
27
+ channel = channel.uid if channel.is_a?(org.openhab.core.thing.Channel)
28
+ t = t.uid if t.is_a?(Thing)
29
+ channel = [t, channel].compact.join(':')
30
+ logger.trace("Creating channel trigger for channel(#{channel}), thing(#{t}), trigger(#{triggered})")
28
31
  [triggered].flatten.each do |trigger|
29
32
  create_channel_trigger(channel, trigger, attach)
30
33
  end
@@ -36,14 +39,13 @@ module OpenHAB
36
39
  #
37
40
  # Create a trigger for a channel
38
41
  #
39
- # @param [Channel] channel to look for triggers
40
- # @param [Trigger] trigger specific channel trigger to match
42
+ # @param [String] channel to look for triggers
43
+ # @param [String] trigger specific channel trigger to match
41
44
  #
42
45
  #
43
46
  def create_channel_trigger(channel, trigger, attach)
44
47
  config = { 'channelUID' => channel }
45
48
  config['event'] = trigger.to_s unless trigger.nil?
46
- config['channelUID'] = channel
47
49
  logger.trace("Creating Change Trigger for #{config}")
48
50
  append_trigger(Trigger::CHANNEL_EVENT, config, attach: attach)
49
51
  end
@@ -14,7 +14,7 @@ module OpenHAB
14
14
  # Support for OpenHAB Things
15
15
  #
16
16
  module Things
17
- java_import Java::OrgOpenhabCoreThing::ThingStatus
17
+ java_import org.openhab.core.thing.ThingStatus
18
18
  include OpenHAB::Log
19
19
 
20
20
  #
@@ -41,6 +41,20 @@ module OpenHAB
41
41
  equals(other)
42
42
  end
43
43
 
44
+ #
45
+ # Case equality
46
+ #
47
+ # @return [Boolean] if the values are of the same Type
48
+ # or item state of the same type
49
+ #
50
+ def ===(other)
51
+ logger.trace("(#{self.class}) #{self} === #{other} (#{other.class})")
52
+ other = other.state if other.respond_to?(:state)
53
+ return false unless instance_of?(other.class)
54
+
55
+ eql?(other)
56
+ end
57
+
44
58
  #
45
59
  # Check equality, including type conversion
46
60
  #
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ java_import org.openhab.core.common.AbstractUID
6
+ java_import org.openhab.core.thing.ThingTypeUID
7
+
8
+ # Adds methods to core OpenHAB AbstractUID to make it more natural in Ruby
9
+ class AbstractUID
10
+ # implicit conversion to string
11
+ alias to_str to_s
12
+ # inspect result is just the string representation
13
+ alias inspect to_s
14
+
15
+ # compares if equal to `other`, including string conversion
16
+ # @return [true, false]
17
+ def ==(other)
18
+ return true if equals(other)
19
+
20
+ to_s == other
21
+ end
22
+ end
23
+
24
+ # Adds methods to core OpenHAB ThingUID to make it more natural in Ruby
25
+ class ThingUID
26
+ # Returns the id of the binding this thing belongs to
27
+ # @return [String]
28
+ def binding_id
29
+ get_segment(0)
30
+ end
31
+ end
32
+
33
+ # Adds methods to core OpenHAB ThingTypeUID to make it more natural in Ruby
34
+ class ThingTypeUID
35
+ # Returns the id of the binding this thing type belongs to
36
+ # @return [String]
37
+ def binding_id
38
+ get_segment(0)
39
+ end
40
+ end
41
+
42
+ # have to remove == from all descendant classes so that they'll inherit
43
+ # the new implementation
44
+ [org.openhab.core.items.MetadataKey,
45
+ org.openhab.core.thing.UID,
46
+ org.openhab.core.thing.ChannelUID,
47
+ org.openhab.core.thing.ChannelGroupUID,
48
+ org.openhab.core.thing.ThingUID,
49
+ org.openhab.core.thing.ThingTypeUID,
50
+ org.openhab.core.thing.type.ChannelTypeUID,
51
+ org.openhab.core.thing.type.ChannelGroupTypeUID].each do |klass|
52
+ klass.remove_method(:==)
53
+ end
54
+ end
55
+ end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.18.0'
8
+ VERSION = '4.19.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.18.0
4
+ version: 4.19.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-30 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,7 @@ files:
136
136
  - lib/openhab/dsl/types/types.rb
137
137
  - lib/openhab/dsl/types/un_def_type.rb
138
138
  - lib/openhab/dsl/types/up_down_type.rb
139
+ - lib/openhab/dsl/uid.rb
139
140
  - lib/openhab/dsl/units.rb
140
141
  - lib/openhab/log/configuration.rb
141
142
  - lib/openhab/log/logger.rb