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

Includes:
Core::EntityLookup, OpenHAB::DSL
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:

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

Constant Summary

Constants included from OpenHAB::DSL

VERSION

Instance Method Summary collapse

Methods included from OpenHAB::DSL

after, between, config_description, debounce_for, ensure_states, ensure_states!, holiday_file, holiday_file!, items, only_every, persistence, persistence!, profile, provider, provider!, rule, rule!, rules, scene, scene!, script, script!, shared_cache, sitemaps, store_states, things, throttle_for, timers, transform, unit, unit!

Methods included from Rules::Terse

#changed, #channel, #channel_linked, #channel_unlinked, #cron, #every, #item_added, #item_removed, #item_updated, #on_start, #received_command, #thing_added, #thing_removed, #thing_updated, #updated

Methods included from Core::ScriptHandling

script_loaded, script_unloaded

Methods included from Core::Actions

notify

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::DSL

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:



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

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:



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

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:



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

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:



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

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:



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

def_item_method(:dimmer)

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

Create a new GroupItem

Parameters:

Yield Parameters:

Returns:



91
92
93
94
95
96
97
98
99
# File 'lib/openhab/dsl/items/builder.rb', line 91

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

def_item_method(:switch)