Class: Switchbot::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/switchbot/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, device_id:) ⇒ Device

Returns a new instance of Device.



7
8
9
10
# File 'lib/switchbot/device.rb', line 7

def initialize(client:, device_id:)
  @client = client
  @device_id = device_id
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/switchbot/device.rb', line 5

def client
  @client
end

#device_idObject (readonly)

Returns the value of attribute device_id.



5
6
7
# File 'lib/switchbot/device.rb', line 5

def device_id
  @device_id
end

Instance Method Details

#commands(command:, parameter: 'default', command_type: 'command') ⇒ Object



16
17
18
# File 'lib/switchbot/device.rb', line 16

def commands(command:, parameter: 'default', command_type: 'command')
  client.commands(device_id: device_id, command: command, parameter: parameter, command_type: command_type)
end

#offObject



24
25
26
# File 'lib/switchbot/device.rb', line 24

def off
  client.commands(device_id: device_id, command: 'turnOff')
end

#off?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/switchbot/device.rb', line 32

def off?
  !on?
end

#onObject



20
21
22
# File 'lib/switchbot/device.rb', line 20

def on
  client.commands(device_id: device_id, command: 'turnOn')
end

#on?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/switchbot/device.rb', line 28

def on?
  status[:body][:power] == 'on'
end

#statusObject



12
13
14
# File 'lib/switchbot/device.rb', line 12

def status
  client.status(device_id: device_id)
end