Module: OpenHAB::DSL::Items::Builder

Includes:
Core::EntityLookup
Included in:
GroupItemBuilder
Defined in:
lib/openhab/dsl/items/builder.rb

Overview

An item builder allows you to dynamically create openHAB items at runtime. This can be useful either to create items as soon as the script loads, or even later based on a rule executing.

Examples:

Create/update JRuby-provided items at runtime

items.build do
  switch_item MySwitch, "My Switch"
  switch_item NotAutoupdating, autoupdate: false, channel: "mqtt:topic:1#light"
  group_item MyGroup do
    contact_item ItemInGroup, channel: "binding:thing#channel"
  end
  # passing `thing` to a group item will automatically use it as the base
  # for item channels
  group_item Equipment, tags: Semantics::HVAC, thing: "binding:thing"
    string_item Mode, tags: Semantics::Control, channel: "mode"
  end

  # dimension Temperature inferred
  number_item OutdoorTemp, format: "%.1f %unit%", unit: "°F"

  # unit lx, dimension Illuminance, format "%s %unit%" inferred
  number_item OutdoorBrightness, state: 10_000 | "lx"
end

Create/update persistent managed-items that are stored in the JSONDB and are editable in the MainUI

items.build(:persistent) do
  switch_item MySwitch, "My Switch"
end

See Also:

Instance Method Summary collapse

Methods included from Core::EntityLookup

#items, #method_missing, #things

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OpenHAB::Core::EntityLookup

Instance Method Details

#call_item(name, label = nil, **kwargs) {|builder| ... } ⇒ CallItem

Create a new call item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



66
# File 'lib/openhab/dsl/items/builder.rb', line 66

def_item_method(:call)

#color_item(name, label = nil, **kwargs) {|builder| ... } ⇒ ColorItem

Create a new color item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



68
# File 'lib/openhab/dsl/items/builder.rb', line 68

def_item_method(:color)

#contact_item(name, label = nil, **kwargs) {|builder| ... } ⇒ ContactItem

Create a new contact item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



70
# File 'lib/openhab/dsl/items/builder.rb', line 70

def_item_method(:contact)

#date_time_item(name, label = nil, **kwargs) {|builder| ... } ⇒ DateTimeItem

Create a new date_time item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



72
# File 'lib/openhab/dsl/items/builder.rb', line 72

def_item_method(:date_time)

#dimmer_item(name, label = nil, **kwargs) {|builder| ... } ⇒ DimmerItem

Create a new dimmer item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



74
# File 'lib/openhab/dsl/items/builder.rb', line 74

def_item_method(:dimmer)

#group_item(name, label = nil, **kwargs) {|builder| ... } ⇒ GroupItem

Create a new GroupItem

Parameters:

Yield Parameters:

Returns:



98
99
100
101
102
103
104
105
106
# File 'lib/openhab/dsl/items/builder.rb', line 98

def group_item(*args, **kwargs, &block)
  item = GroupItemBuilder.new(*args, provider: provider, **kwargs)
  item.instance_eval(&block) if block
  result = provider.add(item)
  item.members.each do |i|
    provider.add(i)
  end
  result
end

#image_item(name, label = nil, **kwargs) {|builder| ... } ⇒ ImageItem

Create a new image item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



76
# File 'lib/openhab/dsl/items/builder.rb', line 76

def_item_method(:image)

#location_item(name, label = nil, **kwargs) {|builder| ... } ⇒ LocationItem

Create a new location item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



78
# File 'lib/openhab/dsl/items/builder.rb', line 78

def_item_method(:location)

#number_item(name, label = nil, **kwargs) {|builder| ... } ⇒ NumberItem

Create a new number item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



80
# File 'lib/openhab/dsl/items/builder.rb', line 80

def_item_method(:number)

#player_item(name, label = nil, **kwargs) {|builder| ... } ⇒ PlayerItem

Create a new player item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



82
# File 'lib/openhab/dsl/items/builder.rb', line 82

def_item_method(:player)

#rollershutter_item(name, label = nil, **kwargs) {|builder| ... } ⇒ RollershutterItem

Create a new rollershutter item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



84
# File 'lib/openhab/dsl/items/builder.rb', line 84

def_item_method(:rollershutter)

#string_item(name, label = nil, **kwargs) {|builder| ... } ⇒ StringItem

Create a new string item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



86
# File 'lib/openhab/dsl/items/builder.rb', line 86

def_item_method(:string)

#switch_item(name, label = nil, **kwargs) {|builder| ... } ⇒ SwitchItem

Create a new switch item

Parameters:

  • name (String, Symbol, Core::Items::Proxy)

    The name for the new item. Note that you can use a string, a symbol, or even a literal constant name

  • label (String) (defaults to: nil)

    The item label

Yield Parameters:

  • builder (ItemBuilder)

    Item for further customization

Returns:

See Also:



88
# File 'lib/openhab/dsl/items/builder.rb', line 88

def_item_method(:switch)