Class: ESPHome::Entities::Lock

Inherits:
ESPHome::Entity show all
Includes:
HasAssumedState, HasState
Defined in:
lib/esphome/entities/lock.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

Constructor Details

#initialize(_device, list_entities_response) ⇒ Lock

Returns a new instance of Lock.



9
10
11
12
13
# File 'lib/esphome/entities/lock.rb', line 9

def initialize(_device, list_entities_response)
  super
  @supports_open = list_entities_response.supports_open
  @requires_code = list_entities_response.requires_code
end

Instance Method Details

#command(command, code = nil) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/esphome/entities/lock.rb', line 27

def command(command, code = nil)
  message = Api::LockCommandRequest.new(key:, command: :"LOCK_#{command.to_s.upcase}")
  if code
    message.code = code
    message.has_code = true
  end
  device.send(message)
end

#lock(code = nil) ⇒ Object



36
# File 'lib/esphome/entities/lock.rb', line 36

def lock(code = nil) = command(:lock, code)

#open(code = nil) ⇒ Object



38
# File 'lib/esphome/entities/lock.rb', line 38

def open(code = nil) = command(:open, code)

#requires_code?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/esphome/entities/lock.rb', line 19

def requires_code?
  @requires_code
end

#supports_open?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/esphome/entities/lock.rb', line 15

def supports_open?
  @supports_open
end

#unlock(code = nil) ⇒ Object



37
# File 'lib/esphome/entities/lock.rb', line 37

def unlock(code = nil) = command(:unlock, code)

#update(state_response) ⇒ Object



23
24
25
# File 'lib/esphome/entities/lock.rb', line 23

def update(state_response)
  @state = (state_response.state == :LOCK_STATE_NONE) ? nil : state_response.state[11..].downcase.to_sym
end