Class: OpenHAB::Core::Sitemaps::Provider

Inherits:
Provider
  • Object
show all
Defined in:
lib/openhab/core/sitemaps/provider.rb

Overview

Provides sitemaps created in Ruby to openHAB

Instance Method Summary collapse

Methods inherited from Provider

#[], #all, current, #inspect

Methods included from Enumerable

#all_groups, #all_members, #command, #command!, #decrease, #down, #equipments, #fast_forward, #groups, #increase, #locations, #member_of, #members, #move, #next, #not_member_of, #not_tagged, #off, #on, #pause, #play, #points, #previous, #refresh, #rewind, #stop, #tagged, #toggle, #up, #update!

Instance Method Details

#build(update: true) { ... } ⇒ void

This method returns an undefined value.

Enter the Sitemap Builder DSL.

Examples:

sitemaps.build do
  sitemap "default", label: "My Residence" do
    frame label: "Control" do
      text label: "Climate", icon: "if:mdi:home-thermometer-outline" do
        frame label: "Main Floor" do
          # colors are set with a hash, with key being condition, and value being the color
          # The :default key is used when no other condition matches
          text item: MainFloor_AmbTemp,
            label_color: "purple", # A simple string can be used when no conditions are needed
            value_color: { ">=90" => "red", "<=70" => "blue", :default => "black" }

          # If item name is not provided in the condition, it will default to the widget's Item
          # The operator will default to == if not specified
          switch item: MainFloorThermostat_TargetMode, label: "Mode",
            mappings: %w[off auto cool heat],
            value_color: { "cool" => "blue", "heat" => "red", :default => "black" }

          # an array of conditions are AND'd together
          setpoint item: MainFloorThermostat_SetPoint, label: "Set Point",
            value_color: {
              ["MainFloorThermostat_TargetMode!=off", ">80"] => "red", # red if mode!=off AND setpoint > 80
              ["MainFloorThermostat_TargetMode!=off", ">74"] => "yellow",
              ["MainFloorThermostat_TargetMode!=off", ">70"] => "green",
              "MainFloorThermostat_TargetMode!=off" => "blue",
              :default => "gray"
            }
        end
        frame label: "Basement" do
          text item: Basement_AmbTemp
          switch item: BasementThermostat_TargetMode, label: "Mode",
            mappings: { OFF: "off", COOL: "cool", HEAT: "heat" }

          # Conditions within a nested array are AND'd together (requires openHAB 4.1)
          setpoint item: BasementThermostat_SetPoint, label: "Set Point",
            visibility: [["BasementThermostat_TargetMode!=off", "Vacation_Switch==OFF"]]

          # Additional elements are OR'd
          # The following visibility conditions are evaluated as:
          # (BasementThermostat_TargetMode!=off AND Vacation_Switch==OFF) OR Verbose_Mode==ON
          setpoint item: BasementThermostat_SetPoint, label: "Set Point",
            visibility: [
              ["BasementThermostat_TargetMode!=off", "Vacation_Switch==OFF"],
              "Verbose_Mode==ON"
            ]
        end
      end
    end
  end
end
def add_tv(builder, tv)
  builder.frame label: tv.location.label do
    builder.switch item: tv.points(Semantics::Switch), label: "Power"
  end
end

sitemaps.build do |builder|
  builder.sitemap "tvs", label: "TVs" do
    items.equipments(Semantics::TV).each do |tv|
      add_tv(builder, tv)
    end
  end
end

Parameters:

  • update (true, false) (defaults to: true)

    When true, existing sitemaps with the same name will be updated.

Yields:

See Also:



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/openhab/core/sitemaps/provider.rb', line 131

def build(update: true, &block)
  builder_proxy = SimpleDelegator.new(nil) if block.arity == 1
  builder = DSL::Sitemaps::Builder.new(self, builder_proxy, update: update)
  if block.arity == 1
    builder_proxy.__setobj__(builder)
    DSL::ThreadLocal.thread_local(openhab_create_dummy_items: true) do
      yield builder_proxy
    end
  else
    builder.instance_eval(&block)
  end
end

#remove(sitemap) ⇒ Boolean

Remove a sitemap.

Parameters:

  • sitemap (String, org.openhab.core.model.sitemap.sitemap.Sitemap)

Returns:

  • (Boolean)

    If a sitemap was removed



165
166
167
168
# File 'lib/openhab/core/sitemaps/provider.rb', line 165

def remove(sitemap)
  sitemap = sitemap.uid if sitemap.respond_to?(:uid)
  super
end

#update(sitemap) ⇒ void

This method returns an undefined value.

Notify listeners about updated sitemap

Parameters:

  • sitemap (String, org.openhab.core.model.sitemap.sitemap.Sitemap)

    The sitemap to update.



150
151
152
153
154
155
156
157
# File 'lib/openhab/core/sitemaps/provider.rb', line 150

def update(sitemap)
  if sitemap.respond_to?(:to_str)
    sitemap = get(sitemap).tap do |obj|
      raise ArgumentError, "Sitemap #{sitemap} not found" unless obj
    end
  end
  super
end