Class: OpenHAB::Core::Items::DimmerItem
- Inherits:
-
SwitchItem
- Object
- GenericItem
- SwitchItem
- OpenHAB::Core::Items::DimmerItem
- Includes:
- NumericItem
- Defined in:
- lib/openhab/core/items/dimmer_item.rb
Overview
A DimmerItem can be used as a switch (ON/OFF), but it also accepts percent values to reflect the dimmed state.
Direct Known Subclasses
Constant Summary
Constants included from Semantics
Semantics::Equipment, Semantics::Location, Semantics::Point, Semantics::Property, Semantics::Tag
Instance Attribute Summary collapse
- #state ⇒ PercentType? readonly
Attributes inherited from GenericItem
#category, #formatted_state, #label, #name, #raw_state, #tags
Attributes included from Semantics
#equipment, #equipment_type, #location, #location_type, #point_type, #property_type, #semantic_type
Attributes included from Item
#accepted_command_types, #accepted_data_types, #all_groups, #channel, #channel_uid, #channel_uids, #channels, #groups, #links, #metadata, #name, #provider, #thing, #things
Instance Method Summary collapse
-
#brighten(amount = 1) ⇒ Integer
Brighten the dimmer.
-
#decrease ⇒ DimmerItem
Send the DECREASE command to the item.
-
#dim(amount = 1) ⇒ Integer
Dim the dimmer.
-
#increase ⇒ DimmerItem
Send the INCREASE command to the item.
Methods inherited from SwitchItem
#off, #off!, #off?, #on, #on!, #on?, #toggle
Methods inherited from GenericItem
#command, #modify, #null?, #refresh, #state?, #time_series=, #undef?, #update
Methods included from Semantics
add, #equipment?, #location?, lookup, #point?, #points, remove, #semantic?, tags
Methods included from Item
#color_item?, #contact_item?, #date_time_item?, #dimmer_item?, #group_item?, #image_item?, #inspect, #link, #location_item?, #member_of?, #number_item?, #player_item?, #rollershutter_item?, #string_item?, #switch_item?, #tagged?, #to_s, #unlink
Methods included from DSL::Items::TimedCommand
Methods included from Persistence
#average_between, #average_since, #changed_between?, #changed_since?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #delta_between, #delta_since, #deviation_between, #deviation_since, #evolution_rate, #historic_state, #last_update, #maximum_between, #maximum_since, #minimum_between, #minimum_since, #persist, #previous_state, #sum_between, #sum_since, #updated_between?, #updated_since?, #variance_between, #variance_since
Methods included from DSL::Items::Ensure::Ensurable
Instance Attribute Details
#state ⇒ PercentType? (readonly)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/openhab/core/items/dimmer_item.rb', line 87 class DimmerItem < SwitchItem include NumericItem # # Dim the dimmer # # @param [Integer] amount to dim by # If 1 is the amount, the DECREASE command is sent, otherwise the # current state - amount is sent as a command. # # @return [Integer] level target for dimmer # # @example # DimmerOne.dim # DimmerOne.dim(2) # def dim(amount = 1) target = [state&.-(amount), 0].compact.max command!(target) target end # # Brighten the dimmer # # @param [Integer] amount to brighten by # If 1 is the amount, the INCREASE command is sent, otherwise the # current state + amount is sent as a command. # # @return [Integer] level target for dimmer # # @example # DimmerOne.brighten # DimmerOne.brighten(2) # def brighten(amount = 1) target = [state&.+(amount), 100].compact.min command!(target) target end # @!method increase # Send the {INCREASE} command to the item # @return [DimmerItem] `self` # @!method decrease # Send the {DECREASE} command to the item # @return [DimmerItem] `self` # raw numbers translate directly to PercentType, not a DecimalType # @!visibility private def format_type(command) return Types::PercentType.new(command) if command.is_a?(Numeric) super end end |
Instance Method Details
#brighten(amount = 1) ⇒ Integer
Brighten the dimmer
current state + amount is sent as a command.
122 123 124 125 126 |
# File 'lib/openhab/core/items/dimmer_item.rb', line 122 def brighten(amount = 1) target = [state&.+(amount), 100].compact.min command!(target) target end |
#decrease ⇒ DimmerItem
Send the DECREASE command to the item
|
# File 'lib/openhab/core/items/dimmer_item.rb', line 132
|
#dim(amount = 1) ⇒ Integer
Dim the dimmer
103 104 105 106 107 |
# File 'lib/openhab/core/items/dimmer_item.rb', line 103 def dim(amount = 1) target = [state&.-(amount), 0].compact.max command!(target) target end |
#increase ⇒ DimmerItem
Send the INCREASE command to the item
|
# File 'lib/openhab/core/items/dimmer_item.rb', line 128
|