Class: OpenHAB::Core::Items::SwitchItem
- Inherits:
-
GenericItem
- Object
- GenericItem
- OpenHAB::Core::Items::SwitchItem
- Defined in:
- lib/openhab/core/items/switch_item.rb
Overview
A SwitchItem represents a normal switch that can be ON or OFF. Useful for normal lights, presence detection etc.
Direct Known Subclasses
Constant Summary
Constants included from Semantics
OpenHAB::Core::Items::Semantics::Equipment, OpenHAB::Core::Items::Semantics::Location, OpenHAB::Core::Items::Semantics::Point, OpenHAB::Core::Items::Semantics::Property, OpenHAB::Core::Items::Semantics::Tag
Instance Attribute Summary collapse
- #state ⇒ OnOffType? 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, #groups, #metadata, #name
Instance Method Summary collapse
-
#off ⇒ SwitchItem
Send the OFF command to the item.
-
#off? ⇒ true, false
Check if the item state == OFF.
-
#on ⇒ SwitchItem
Send the ON command to the item.
-
#on? ⇒ true, false
Check if the item state == ON.
-
#toggle ⇒ self
Send a command to invert the state of the switch.
Methods inherited from GenericItem
#command, #modify, #null?, #refresh, #state?, #undef?, #update
Methods included from Semantics
#equipment?, #location?, #point?, #points, #semantic?
Methods included from Item
#inspect, #member_of?, #provider, #tagged?, #thing, #things, #to_s
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 ⇒ OnOffType? (readonly)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/openhab/core/items/switch_item.rb', line 38 class SwitchItem < GenericItem # Convert boolean commands to ON/OFF # @!visibility private def format_type(command) return Types::OnOffType.from(command) if [true, false].include?(command) super end # # Send a command to invert the state of the switch # # @return [self] # def toggle return on unless state? command(!state) end # @!method on? # Check if the item state == {ON} # @return [true,false] # @!method off? # Check if the item state == {OFF} # @return [true,false] # @!method on # Send the {ON} command to the item # @return [SwitchItem] `self` # @!method off # Send the {OFF} command to the item # @return [SwitchItem] `self` end |
Instance Method Details
#off ⇒ SwitchItem
Send the OFF command to the item
|
# File 'lib/openhab/core/items/switch_item.rb', line 70
|
#off? ⇒ true, false
Check if the item state == OFF
|
# File 'lib/openhab/core/items/switch_item.rb', line 62
|
#on ⇒ SwitchItem
Send the ON command to the item
|
# File 'lib/openhab/core/items/switch_item.rb', line 66
|
#on? ⇒ true, false
Check if the item state == ON
|
# File 'lib/openhab/core/items/switch_item.rb', line 58
|
#toggle ⇒ self
Send a command to invert the state of the switch
52 53 54 55 56 |
# File 'lib/openhab/core/items/switch_item.rb', line 52 def toggle return on unless state? command(!state) end |