Class: OpenHAB::DSL::Sitemaps::ButtongridBuilder

Inherits:
LinkableWidgetBuilder show all
Defined in:
lib/openhab/dsl/sitemaps/builder.rb

Overview

Builds a Buttongrid element

Defined Under Namespace

Modules: Buttongrid

Instance Attribute Summary

Attributes inherited from WidgetBuilder

#icon, #icon_colors, #item, #label, #label_colors, #static_icon, #value_colors, #visibilities

Instance Method Summary collapse

Methods inherited from LinkableWidgetBuilder

#buttongrid, #chart, #colorpicker, #default, #frame, #group, #image, #input, #mapview, #selection, #setpoint, #slider, #switch, #text, #video, #webview

Methods inherited from WidgetBuilder

#icon_color, #label_color, #value_color, #visibility

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

#button(row = nil, column = nil, click = nil, label = nil, icon = nil, item: nil, label: nil, icon: nil, static_icon: nil, row: , column: , click: , release: nil, stateless: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil) ⇒ ButtonBuilder

Adds a button inside the buttongrid

  • In openHAB 4.1, buttons are direct properties of the buttongrid. Only row, column, click, label (optional), and icon (optional) are used. All the other parameters are ignored. All the buttons will send commands to the same item assigned to the buttongrid.

  • In openHAB 4.2+, buttons are widgets within the containing buttongrid, and they support all the parameters listed in the method signature such as release, label_color, visibility, etc. Each Button element has an item associated with that button. When an item is not specified for the button, it will default to the containing buttongrid's item.

This method supports positional arguments and/or keyword arguments. Their use can be mixed, however, the keyword arguments will override the positional arguments when both are specified.

Examples:

Adding buttons to a buttongrid with positional arguments

sitemaps.build do
  sitemap "remote" do
    buttongrid item: RCButton do
      button 1, 1, "BACK", "Back", "f7:return"
      button 1, 2, "HOME", "Menu", "material:apps"
      button 1, 3, "YELLOW", "Search", "f7:search"
      button 2, 2, "UP", "Up", "f7:arrowtriangle_up"
      button 4, 2, "DOWN", "Down", "f7:arrowtriangle_down"
      button 3, 1, "LEFT", "Left", "f7:arrowtriangle_left"
      button 3, 3, "RIGHT", "Right", "f7:arrowtriangle_right"
      button 3, 2, "ENTER", "Enter", "material:adjust"
    end
  end
end

Adding buttons to a buttongrid with keyword arguments

sitemaps.build do
  sitemap "remote" do
    buttongrid item: RCButton do
      # These buttons will use the default item assigned to the buttongrid (RCButton)
      button row: 1, column: 1, click: "BACK", icon: "f7:return"
      button row: 1, column: 2, click: "HOME", icon: "material:apps"
      button row: 1, column: 3, click: "YELLOW", icon: "f7:search"
      button row: 2, column: 2, click: "UP", icon: "f7:arrowtriangle_up"
      button row: 4, column: 2, click: "DOWN", icon: "f7:arrowtriangle_down"
      button row: 3, column: 1, click: "LEFT", icon: "f7:arrowtriangle_left"
      button row: 3, column: 3, click: "RIGHT", icon: "f7:arrowtriangle_right"
      button row: 3, column: 2, click: "ENTER", icon: "material:adjust"
    end
  end
end

Mixing positional and keyword arguments

sitemaps.build do
  sitemap "remote" do
    buttongrid item: RCButton do
      button 1, 1, click: "BACK", icon: "f7:return"
      button 1, 2, click: "HOME", icon: "material:apps"
      button 1, 3, click: "YELLOW", icon: "f7:search"
      button 2, 2, click: "UP", icon: "f7:arrowtriangle_up"
      button 4, 2, click: "DOWN", icon: "f7:arrowtriangle_down"
      button 3, 1, click: "LEFT", icon: "f7:arrowtriangle_left"
      button 3, 3, click: "RIGHT", icon: "f7:arrowtriangle_right"
      button 3, 2, click: "ENTER", icon: "material:adjust"
    end
  end
end

openHAB 4.2+ supports assigning different items to buttons, along with additional features

sitemaps.build do
  sitemap "remote" do
    buttongrid item: RCButton do
      button 1, 1, click: "BACK", icon: "f7:return"
      button 1, 2, click: "HOME", icon: "material:apps"
      button 1, 3, click: "YELLOW", icon: "f7:search", icon_color: "yellow"
      button 2, 2, click: "UP", icon: "f7:arrowtriangle_up"
      button 4, 2, click: "DOWN", icon: "f7:arrowtriangle_down"
      button 3, 1, click: "LEFT", icon: "f7:arrowtriangle_left"
      button 3, 3, click: "RIGHT", icon: "f7:arrowtriangle_right"
      button 3, 2, click: "ENTER", icon: "material:adjust", icon_color: "red"

      # These buttons will use the specified item, only supported in openHAB 4.2+
      button 4, 3, click: ON, static_icon: "switch-off", visibility: "TVPower!=ON", item: TVPower
      button 4, 3, click: OFF, static_icon: "switch-on", visibility: "TVPower==ON", item: TVPower
    end
  end
end

Parameters:

Returns:

Since:

  • openHAB 4.1



1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
# File 'lib/openhab/dsl/sitemaps/builder.rb', line 1391

def button(row = nil, column = nil, click = nil, label = nil, icon = nil, **kwargs, &block)
  args = [row, column, click, label, icon].compact

  args = args.first if args.first.is_a?(Array)
  kwargs = %i[row column click label icon].zip(args).to_h.compact.merge(kwargs)

  missing_args = (REQUIRED_BUTTON_ARGS - kwargs.keys).compact
  unless missing_args.empty?
    args = kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")
    missing_args = missing_args.map(&:to_s).join(", ")
    raise ArgumentError, "button(#{args}) missing required parameters: #{missing_args}"
  end

  kwargs[:item] ||= item if item # default to the buttongrid's item
  kwargs[:label] ||= kwargs[:click].to_s

  ButtonBuilder.new(@builder_proxy, **kwargs, &block).tap do |b|
    children << b
  end
end