openhab-scripting 5.12.0 → 5.13.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: 35d0d28ba4dd272f12cd989761c2d615836d25dbafbc2af2b60692f8a535d5c1
4
- data.tar.gz: 4d51dd07a43f5ff7a7ad43bc66cbb1d63b320486a82036d1a8cbfb22412a061b
3
+ metadata.gz: bfe5a24aad596dbbc699c68d39ffec4417b9199a75738a54292386d80e725525
4
+ data.tar.gz: 7aa7877384c2df3ee41588660e3db596f807fd5b2b7b781921528f14b0f9fdeb
5
5
  SHA512:
6
- metadata.gz: 76c075f22df43c0ecfe37775e297f496d2f55fe60e6da95bbece311d92fe3e37e50d867a23f6f52c3ebeb690771e7eb5512c357ca3b0745d83d03a8df892cad7
7
- data.tar.gz: 93eb532732729b91437a669fbbe9b0b024397332faa435c82ebe17d50c4ea4a29576108c819010c0a497a5912d74eaa95e87fc0d98b01f9fa0987fbb52b5fa7b
6
+ metadata.gz: 756ab20dcfdfce97ba6dfdcbf76d1f40c544607312622e0e013ddd38f7a0d201ae0fec69c13017300fba938d7081eb89f5be5d65ad59abcadf17380ae580dad8
7
+ data.tar.gz: d9facdcb106fe9fa3e2e51574fa2e52168b9c07eb9c1fad1498a6380e9bc783c8a63535c2a715956a894eb39a2b741ff6f9284fb1de71f9e083262b9f4ed42d0
@@ -4,7 +4,7 @@ module OpenHAB
4
4
  module Core
5
5
  java_import org.openhab.core.common.AbstractUID
6
6
 
7
- # Adds methods to core openHAB AbstractUID to make it more natural in Ruby
7
+ # A non specific base class for unique identifiers.
8
8
  class AbstractUID
9
9
  # implicit conversion to string
10
10
  alias_method :to_str, :to_s
@@ -52,8 +52,6 @@ module OpenHAB
52
52
  @registration.unregister
53
53
  end
54
54
 
55
- # rubocop:disable Layout/LineLength
56
-
57
55
  #
58
56
  # Enter the Sitemap Builder DSL.
59
57
  #
@@ -69,18 +67,45 @@ module OpenHAB
69
67
  # frame label: "Control" do
70
68
  # text label: "Climate", icon: "if:mdi:home-thermometer-outline" do
71
69
  # frame label: "Main Floor" do
72
- # text item: MainFloor_AmbTemp
73
70
  # # colors are set with a hash, with key being condition, and value being the color
74
- # switch item: MainFloorThermostat_TargetMode, label: "Mode", mappings: %w[off auto cool heat], label_color: { "==heat" => "red", "" => "black" }
75
- # # an array of conditions are OR'd together
76
- # switch item: MainFloorThermostat_TargetMode, label: "Mode", mappings: %w[off auto cool heat], label_color: { ["==heat", "==cool"], => "green" }
77
- # setpoint item: MainFloorThermostat_SetPoint, label: "Set Point", visibility: "MainFloorThermostat_TargetMode!=off"
71
+ # # The :default key is used when no other condition matches
72
+ # text item: MainFloor_AmbTemp,
73
+ # label_color: "purple", # A simple string can be used when no conditions are needed
74
+ # value_color: { ">=90" => "red", "<=70" => "blue", :default => "black" }
75
+ #
76
+ # # If item name is not provided in the condition, it will default to the widget's Item
77
+ # # The operator will default to == if not specified
78
+ # switch item: MainFloorThermostat_TargetMode, label: "Mode",
79
+ # mappings: %w[off auto cool heat],
80
+ # value_color: { "cool" => "blue", "heat" => "red", :default => "black" }
81
+ #
82
+ # # an array of conditions are AND'd together
83
+ # setpoint item: MainFloorThermostat_SetPoint, label: "Set Point",
84
+ # value_color: {
85
+ # ["MainFloorThermostat_TargetMode!=off", ">80"] => "red", # red if mode!=off AND setpoint > 80
86
+ # ["MainFloorThermostat_TargetMode!=off", ">74"] => "yellow",
87
+ # ["MainFloorThermostat_TargetMode!=off", ">70"] => "green",
88
+ # "MainFloorThermostat_TargetMode!=off" => "blue",
89
+ # :default => "gray"
90
+ # }
78
91
  # end
79
92
  # frame label: "Basement" do
80
93
  # text item: Basement_AmbTemp
81
- # switch item: BasementThermostat_TargetMode, label: "Mode", mappings: { OFF: "off", COOL: "cool", HEAT: "heat" }
82
- # # nested arrays are conditions that are AND'd together, instead of OR'd (requires openHAB 4.1)
83
- # setpoint item: BasementThermostat_SetPoint, label: "Set Point", visibility: [["BasementThermostat_TargetMode!=off", "Vacation_Switch!=OFF"]]
94
+ # switch item: BasementThermostat_TargetMode, label: "Mode",
95
+ # mappings: { OFF: "off", COOL: "cool", HEAT: "heat" }
96
+ #
97
+ # # Conditions within a nested array are AND'd together (requires openHAB 4.1)
98
+ # setpoint item: BasementThermostat_SetPoint, label: "Set Point",
99
+ # visibility: [["BasementThermostat_TargetMode!=off", "Vacation_Switch==OFF"]]
100
+ #
101
+ # # Additional elements are OR'd
102
+ # # The following visibility conditions are evaluated as:
103
+ # # (BasementThermostat_TargetMode!=off AND Vacation_Switch==OFF) OR Verbose_Mode==ON
104
+ # setpoint item: BasementThermostat_SetPoint, label: "Set Point",
105
+ # visibility: [
106
+ # ["BasementThermostat_TargetMode!=off", "Vacation_Switch==OFF"],
107
+ # "Verbose_Mode==ON"
108
+ # ]
84
109
  # end
85
110
  # end
86
111
  # end
@@ -90,7 +115,6 @@ module OpenHAB
90
115
  def build(update: true, &block)
91
116
  DSL::Sitemaps::Builder.new(self, update: update).instance_eval(&block)
92
117
  end
93
- # rubocop:enable Layout/LineLength
94
118
 
95
119
  # For use in specs
96
120
  # @!visibility private
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ java_import org.openhab.core.thing.type.AbstractDescriptionType
7
+
8
+ #
9
+ # Base class for {ThingType}, {ChannelType}, and {ChannelGroupType}
10
+ #
11
+ # @!attribute [r] label
12
+ # @return [String]
13
+ #
14
+ # @!attribute [r] description
15
+ # @return [String, nil]
16
+ #
17
+ class AbstractDescriptionType # rubocop:disable Lint/EmptyClass
18
+ end
19
+ end
20
+ end
21
+ end
@@ -23,6 +23,9 @@ module OpenHAB
23
23
  # @!attribute [r] uid
24
24
  # @return [ChannelUID]
25
25
  #
26
+ # @!attribute [r] channel_type_uid
27
+ # @return [ChannelTypeUID]
28
+ #
26
29
  class Channel
27
30
  extend Forwardable
28
31
 
@@ -43,6 +46,12 @@ module OpenHAB
43
46
  "#{r}>"
44
47
  end
45
48
 
49
+ # @!attribute [r] channel_type
50
+ # @return [ChannelType]
51
+ def channel_type
52
+ ChannelType.registry.get_channel_type(channel_type_uid)
53
+ end
54
+
46
55
  # @return [String]
47
56
  def to_s
48
57
  uid.to_s
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Things
8
+ java_import org.openhab.core.thing.type.ChannelDefinition
9
+
10
+ #
11
+ # {ChannelDefinition} is a part of a {ChannelGroupType} that represents a functionality of it.
12
+ # Therefore {Item Items} can be linked a to a channel.
13
+ #
14
+ # @!attribute [r] id
15
+ # @return [String]
16
+ #
17
+ # @!attribute [r] label
18
+ # @return [String, nil]
19
+ #
20
+ # @!attribute [r] description
21
+ # @return [String, nil]
22
+ #
23
+ # @!attribute [r] channel_type_uid
24
+ # @return [ChannelTypeUID]
25
+ #
26
+ # @!attribute [r] channel_type
27
+ # (see ChannelTypeUID#channel_type)
28
+ #
29
+ # @!attribute [r] properties
30
+ # @return [Hash<String, String>]
31
+ #
32
+ class ChannelDefinition
33
+ extend Forwardable
34
+
35
+ delegate channel_type: :channel_type_uid
36
+
37
+ # @!attribute [r] auto_update_policy
38
+ # @return [:veto, :default, :recommend, nil]
39
+ def auto_update_policy
40
+ get_auto_update_policy&.to_s&.downcase&.to_sym
41
+ end
42
+
43
+ # @return [String]
44
+ def inspect
45
+ r = "#<OpenHAB::Core::Things::ChannelDefinition #{id}"
46
+ r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
47
+ r += " #{label.inspect}" if label
48
+ r += " description=#{description.inspect}" if description
49
+ r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
50
+ r += " properties=#{properties.to_h}" unless properties.empty?
51
+ "#{r}>"
52
+ end
53
+
54
+ # @return [String]
55
+ def to_s
56
+ id.to_s
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Things
8
+ java_import org.openhab.core.thing.type.ChannelGroupDefinition
9
+
10
+ #
11
+ # {ChannelGroupDefinition} is a part of a {ThingType} that represents a set of channels
12
+ #
13
+ # @!attribute [r] id
14
+ # @return [String]
15
+ #
16
+ # @!attribute [r] label
17
+ # @return [String, nil]
18
+ #
19
+ # @!attribute [r] description
20
+ # @return [String, nil]
21
+ #
22
+ # @!attribute [r] channel_group_type_uid
23
+ # @return [ChannelGroupTypeUID]
24
+ #
25
+ # @!attribute [r] channel_group_type
26
+ # (see ChannelGroupTypeUID#channel_group_type)
27
+ #
28
+ class ChannelGroupDefinition
29
+ extend Forwardable
30
+
31
+ alias_method :channel_group_type_uid, :type_uid
32
+
33
+ delegate channel_group_type: :channel_group_type_uid
34
+
35
+ # @return [String]
36
+ def inspect
37
+ r = "#<OpenHAB::Core::Things::ChannelGroupDefinition #{id}"
38
+ r += " channel_group_type_uid=#{channel_group_type_uid.inspect}"
39
+ r += " #{label.inspect}" if label
40
+ r += " description=#{description.inspect}" if description
41
+ "#{r}>"
42
+ end
43
+
44
+ # @return [String]
45
+ def to_s
46
+ id.to_s
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ java_import org.openhab.core.thing.type.ChannelGroupType
7
+
8
+ #
9
+ # {ChannelGroupType} contains a list of
10
+ # {ChannelDefinition channel definitions} and further meta information
11
+ # such as label and description, which are generally used by user
12
+ # interfaces.
13
+ #
14
+ # @!attribute [r] uid
15
+ # @return [ChannelGroupTypeUID]
16
+ #
17
+ # @!attribute [r] channel_definitions
18
+ # @return [Array<ChannelDefinition>]
19
+ #
20
+ # @!attribute [r] category
21
+ # @return [String, nil]
22
+ #
23
+ class ChannelGroupType < AbstractDescriptionType
24
+ class << self
25
+ # @!visibility private
26
+ def registry
27
+ @registry ||= OSGi.service("org.openhab.core.thing.type.ChannelGroupTypeRegistry")
28
+ end
29
+ end
30
+
31
+ # @return [String]
32
+ def inspect
33
+ r = "#<OpenHAB::Core::Things::ChannelGroupType #{uid}"
34
+ r += " category=#{category.inspect}" if category
35
+ "#{r}>"
36
+ end
37
+
38
+ # @return [String]
39
+ def to_s
40
+ uid.to_s
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require_relative "uid"
6
+
7
+ module OpenHAB
8
+ module Core
9
+ module Things
10
+ java_import org.openhab.core.thing.type.ChannelGroupTypeUID
11
+
12
+ #
13
+ # {ChannelGroupTypeUID} represents a unique identifier for a {ChannelGroupType}.
14
+ #
15
+ # @!attribute [r] id
16
+ # @return [String]
17
+ #
18
+ # @!attribute [r] channel_definitions
19
+ # (see ChannelGroupType#channel_definitions)
20
+ #
21
+ # @!attribute [r] category
22
+ # (see ChannelGroupType#category)
23
+ #
24
+ class ChannelGroupTypeUID < UID
25
+ extend Forwardable
26
+
27
+ delegate %i[category channel_definitions] => :channel_group_type
28
+
29
+ # @!attribute [r] channel_group_type
30
+ # @return [ChannelGroupType]
31
+ def channel_group_type
32
+ ChannelGroupType.registry.get_channel_group_type(self)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require_relative "uid"
6
+
7
+ module OpenHAB
8
+ module Core
9
+ module Things
10
+ java_import org.openhab.core.thing.ChannelGroupUID
11
+
12
+ #
13
+ # {ChannelGroupUID} represents a unique identifier for a group of channels.
14
+ #
15
+ # @!attribute [r] id
16
+ # @return [String]
17
+ #
18
+ # @!attribute [r] thing_uid
19
+ # @return [ThingUID]
20
+ #
21
+ class ChannelGroupUID < UID
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Things
8
+ java_import org.openhab.core.thing.type.ChannelType
9
+
10
+ #
11
+ # {ChannelGroupType} contains a list of
12
+ # {ChannelDefinition channel definitions} and further meta information
13
+ # such as label and description, which are generally used by user
14
+ # interfaces.
15
+ #
16
+ # @!attribute [r] uid
17
+ # @return [ChannelTypeUID]
18
+ #
19
+ # @!attribute [r] item_type
20
+ # @return [String]
21
+ #
22
+ # @!attribute [r] tags
23
+ # @return [Set<String>]
24
+ #
25
+ # @!attribute [r] category
26
+ # @return [String, nil]
27
+ #
28
+ class ChannelType < AbstractDescriptionType
29
+ class << self
30
+ # @!visibility private
31
+ def registry
32
+ @registry ||= OSGi.service("org.openhab.core.thing.type.ChannelTypeRegistry")
33
+ end
34
+ end
35
+
36
+ # @!attribute [r] kind
37
+ # @return [:state, :trigger]
38
+ def kind
39
+ get_kind.to_s.to_sym
40
+ end
41
+
42
+ # @!attribute [r] advanced?
43
+ # @return [true, false]
44
+ alias_method :advanced?, :advanced
45
+
46
+ # @!visibility private
47
+ alias_method :state_description, :state
48
+
49
+ # @!attribute [r] auto_update_policy
50
+ # @return [:veto, :default, :recommend, nil]
51
+ def auto_update_policy
52
+ get_auto_update_policy&.to_s&.downcase&.to_sym
53
+ end
54
+
55
+ # @return [String]
56
+ def inspect
57
+ r = "#<OpenHAB::Core::Things::ChannelType #{uid}"
58
+ r += " (#{kind})" unless kind == :state
59
+ r += " (advanced)" if advanced?
60
+ r += " item_type=#{item_type}"
61
+ r += " tags=(#{tags.join(", ")})" unless tags.empty?
62
+ r += " category=#{category.inspect}" if category
63
+ r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
64
+ "#{r}>"
65
+ end
66
+
67
+ # @return [String]
68
+ def to_s
69
+ uid.to_s
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require_relative "uid"
6
+
7
+ module OpenHAB
8
+ module Core
9
+ module Things
10
+ java_import org.openhab.core.thing.type.ChannelTypeUID
11
+
12
+ #
13
+ # {ChannelTypeUID} represents a unique identifier for a {ChannelType}.
14
+ #
15
+ # @!attribute [r] id
16
+ # @return [String]
17
+ #
18
+ # @!attribute [r] item_type
19
+ # (see ChannelType#item_type)
20
+ #
21
+ # @!attribute [r] tags
22
+ # (see ChannelType#tags)
23
+ #
24
+ # @!attribute [r] category
25
+ # (see ChannelType#category)
26
+ #
27
+ # @!attribute [r] auto_update_policy
28
+ # (see ChannelType#auto_update_policy)
29
+ #
30
+ class ChannelTypeUID < UID
31
+ extend Forwardable
32
+
33
+ # @!method advanced?
34
+ # @return [true, false]
35
+
36
+ delegate %i[item_type
37
+ tags
38
+ category
39
+ auto_update_policy
40
+ command_description
41
+ event_description
42
+ state_description
43
+ advanced?] => :channel_type
44
+
45
+ # @!attribute [r] channel_type
46
+ # @return [ChannelType]
47
+ def channel_type
48
+ ChannelType.registry.get_channel_type(self)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -2,15 +2,32 @@
2
2
 
3
3
  require "forwardable"
4
4
 
5
+ require_relative "uid"
6
+
5
7
  module OpenHAB
6
8
  module Core
7
9
  module Things
8
10
  java_import org.openhab.core.thing.ChannelUID
9
11
 
10
12
  #
11
- # {ChannelUID} represents a unique identifier for {Channel channels}.
13
+ # {ChannelUID} represents a unique identifier for a {Channel}.
14
+ #
15
+ # @!attribute [r] id
16
+ # @return [String]
17
+ #
18
+ # @!attribute [r] id_without_group
19
+ # @return [String]
12
20
  #
13
- class ChannelUID
21
+ # @!attribute [r] group_id
22
+ # @return [String, nil]
23
+ #
24
+ # @!attribute [r] thing_uid
25
+ # @return [ThingUID]
26
+ #
27
+ class ChannelUID < UID
28
+ # @return [true, false]
29
+ alias_method :in_group?, :is_in_group
30
+
14
31
  #
15
32
  # @attribute [r] thing
16
33
  #
@@ -39,11 +39,14 @@ module OpenHAB
39
39
  #
40
40
  # @!attribute [r] uid
41
41
  # Return the UID.
42
- # @return [org.openhab.core.thing.ThingUID]
42
+ # @return [ThingUID]
43
43
  #
44
44
  # @!attribute [r] bridge_uid
45
45
  # Return the Bridge UID when available.
46
- # @return [org.openhab.core.thing.ThingUID]
46
+ # @return [ThingUID]
47
+ #
48
+ # @!attribute [r] thing_type_uid
49
+ # @return [ThingTypeUID]
47
50
  #
48
51
  # @!attribute [r] configuration
49
52
  # Return the thing's configuration.
@@ -156,6 +159,12 @@ module OpenHAB
156
159
  enable(enabled: false)
157
160
  end
158
161
 
162
+ # @!attribute [r] thing_type
163
+ # @return [ThingType]
164
+ def thing_type
165
+ ThingType.registry.get_thing_type(thing_type_uid)
166
+ end
167
+
159
168
  # @return [String]
160
169
  def inspect
161
170
  r = "#<OpenHAB::Core::Things::Thing #{uid}"
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ java_import org.openhab.core.thing.type.ThingType
7
+
8
+ #
9
+ # {ThingType} contains a list of
10
+ # {ChannelGroupDefinition channel group definitions},
11
+ # {ChannelDefinition channel definitions} and further meta information.
12
+ #
13
+ # This description is used as template definition for the creation of the
14
+ # according concrete {Thing} object.
15
+ #
16
+ # @!attribute [r] uid
17
+ # @return [ChannelGroupTypeUID]
18
+ #
19
+ # @!attribute [r] channel_group_definitions
20
+ # @return [Array<ChannelGroupDefinition>]
21
+ #
22
+ # @!attribute [r] channel_definitions
23
+ # @return [Array<ChannelDefinition>]
24
+ #
25
+ # @!attribute [r] supported_bridge_type_uids
26
+ # @return [Array<String>]
27
+ #
28
+ # @!attribute [r] category
29
+ # @return [String, nil]
30
+ #
31
+ # @!attribute [r] properties
32
+ # @return [Hash<String, String>]
33
+ #
34
+ class ThingType < AbstractDescriptionType
35
+ class << self
36
+ # @!visibility private
37
+ def registry
38
+ @registry ||= OSGi.service("org.openhab.core.thing.type.ThingTypeRegistry")
39
+ end
40
+ end
41
+
42
+ # @!attribute [r] listed?
43
+ # @return [true, false]
44
+ alias_method :listed?, :is_listed
45
+
46
+ # @return [String]
47
+ def inspect
48
+ r = "#<OpenHAB::Core::Things::ThingType #{uid}"
49
+ r += " (unlisted)" unless listed?
50
+ r += " category=#{category.inspect}" if category
51
+ r += " properties=#{properties.to_h}" unless properties.empty?
52
+ "#{r}>"
53
+ end
54
+
55
+ # @return [String]
56
+ def to_s
57
+ uid.to_s
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require_relative "uid"
6
+
7
+ module OpenHAB
8
+ module Core
9
+ module Things
10
+ java_import org.openhab.core.thing.ThingTypeUID
11
+
12
+ #
13
+ # {ThingTypeUID} represents a unique identifier for a {ThingType}.
14
+ #
15
+ # @!attribute [r] id
16
+ # @return [String]
17
+ #
18
+ # @!attribute [r] channel_group_definitions
19
+ # (see ThingType#channel_group_definitions)
20
+ #
21
+ # @!attribute [r] channel_definitions
22
+ # (see ThingType#channel_definitions)
23
+ #
24
+ # @!attribute [r] supported_bridge_type_uids
25
+ # (see ThingType#supported_bridge_type_uids)
26
+ #
27
+ # @!attribute [r] category
28
+ # (see ThingType#category)
29
+ #
30
+ # @!attribute [r] properties
31
+ # (see ThingType#properties)
32
+ #
33
+ class ThingTypeUID < UID
34
+ extend Forwardable
35
+
36
+ # @!method listed?
37
+ # @return [true, false]
38
+
39
+ delegate %i[channel_group_definitions
40
+ channel_definitions
41
+ supported_bridge_type_uids
42
+ category
43
+ properties
44
+ listed?] => :thing_type
45
+
46
+ # @!attribute [r] thing_type
47
+ # @return [ThingType]
48
+ def thing_type
49
+ ThingType.registry.get_thing_type(self)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end