class Switchbot::Device

Attributes

client[R]
device_id[R]

Public Class Methods

new(client:, device_id:) click to toggle source
# File lib/switchbot/device.rb, line 7
def initialize(client:, device_id:)
  @client = client
  @device_id = device_id
end

Public Instance Methods

commands(command:, parameter: 'default', command_type: 'command') click to toggle source
# 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
off() click to toggle source
# File lib/switchbot/device.rb, line 24
def off
  client.commands(device_id: device_id, command: 'turnOff')
end
off?() click to toggle source
# File lib/switchbot/device.rb, line 32
def off?
  !on?
end
on() click to toggle source
# File lib/switchbot/device.rb, line 20
def on
  client.commands(device_id: device_id, command: 'turnOn')
end
on?() click to toggle source
# File lib/switchbot/device.rb, line 28
def on?
  status[:body][:power] == 'on'
end
status() click to toggle source
# File lib/switchbot/device.rb, line 12
def status
  client.status(device_id: device_id)
end