Class: ESPHome::Entities::Switch

Inherits:
ESPHome::Entity show all
Includes:
HasAssumedState, HasDeviceClass, HasState
Defined in:
lib/esphome/entities/switch.rb

Instance Attribute Summary

Attributes inherited from ESPHome::Entity

#device, #disabled_by_default, #entity_category, #icon, #key, #name, #object_id_

Instance Method Summary collapse

Methods inherited from ESPHome::Entity

#inspect

Instance Method Details

#command(state) ⇒ Object



14
15
16
# File 'lib/esphome/entities/switch.rb', line 14

def command(state)
  device.send(Api::SwitchCommandRequest.new(key:, state:))
end

#formatted_stateObject



18
# File 'lib/esphome/entities/switch.rb', line 18

def formatted_state = state ? "on" : "off"

#offObject



21
# File 'lib/esphome/entities/switch.rb', line 21

def off = command(false)

#onObject



20
# File 'lib/esphome/entities/switch.rb', line 20

def on = command(true)

#update(state_response) ⇒ Object



10
11
12
# File 'lib/esphome/entities/switch.rb', line 10

def update(state_response)
  @state = state_response.state
end