class TPLink::Device

Generic class for all TPLink devices0

Attributes

alias[R]

Returns alais of device. @return [String] Device alias (name in kasa app).

fw_id[R]

@!visibility private

fw_version[R]

@!visibility private

hw_id[R]

@!visibility private

hw_version[R]

@!visibility private

id[R]

@!visibility private

mac[R]

@!visibility private

model[R]

@!visibility private

name[R]

Returns name of device. @return [String] Name of device (e.g. TP Link Smart Plug).

role[R]

@!visibility private

same_region[R]

@!visibility private

status[R]

Returns satus of device. @return [Boolean<1>] if device is on. @return [Boolean<0>] if device is off.

type[R]

@!visibility private

url[R]

@!visibility private

Public Class Methods

new(parent, dev) click to toggle source

@!visibility private This should only be called internally

# File lib/tp_link/device.rb, line 26
def initialize(parent, dev)
  @parent = parent
  @alias = dev['alias']
  @name = dev['deviceName']
  @status = dev['status']
  @type = dev['deviceType']
  @url = dev['appServerUrl']
  @model = dev['deviceModel']
  @mac = dev['deviceMac']
  @role = dev['role']
  @same_region = dev['isSameRegion']
  @hw_id = dev['hwId']
  @fw_id = dev['fwId']
  @id = dev['deviceId']
  @hw_version = dev['deviceHwVersion']
  @fw_version = dev['fwVer']
end

Public Instance Methods

off() click to toggle source

Turn device off

# File lib/tp_link/device.rb, line 71
def off; end
off?() click to toggle source

@return [True] if device is off. @return [False] if device is on.

# File lib/tp_link/device.rb, line 82
def off?
  !on?
end
on() click to toggle source

Turn device on

# File lib/tp_link/device.rb, line 68
def on; end
on?() click to toggle source

@return [True] if device is on. @return [False] if device is off.

# File lib/tp_link/device.rb, line 75
def on?
  reload
  @status == 1
end
reload() click to toggle source

Reload data / device state

# File lib/tp_link/device.rb, line 52
def reload
  res = @parent.send_data(self,
                          "system":
                           { "get_sysinfo": nil },
                          "emeter": { "get_realtime": nil })
  @rssi = res['responseData']['system']['get_sysinfo']['rssi']
  case self.class.to_s
  when 'TPLink::Light'
    reload_light(res)
  when 'TPLink::Plug'
    reload_plug(res)
  end
  true
end
rssi() click to toggle source

Get Wifi signal strength in dB @returns [Integer]

# File lib/tp_link/device.rb, line 46
def rssi
  reload
  @rssi
end

Private Instance Methods

reload_light(res) click to toggle source
# File lib/tp_link/device.rb, line 92
def reload_light(res)
  @status = res['responseData']['system']['get_sysinfo']['light_state']['on_off']
end
reload_plug(res) click to toggle source
# File lib/tp_link/device.rb, line 88
def reload_plug(res)
  @status = res['responseData']['system']['get_sysinfo']['relay_state']
end
reload_rgb(res) click to toggle source
# File lib/tp_link/device.rb, line 96
def reload_rgb(res)
  # TODO: Add variables for Hue, and Saturation
  @status = res['responseData']['system']['get_sysinfo']['light_state']['on_off']
end