Class: Kasa::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/kasa/devices.rb

Overview

Common methods across kasa devices

Direct Known Subclasses

NonDimmable

Constant Summary collapse

ON =
1
OFF =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, args) ⇒ Device

initialize



12
13
14
15
16
17
18
# File 'lib/kasa/devices.rb', line 12

def initialize(ip, args)
  @ip = ip
  @alias = args['alias']
  @model = args['model']
  @dev_name = args['dev_name']
  @mac = args['mac']
end

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



9
10
11
# File 'lib/kasa/devices.rb', line 9

def alias
  @alias
end

#dev_nameObject (readonly)

Returns the value of attribute dev_name.



9
10
11
# File 'lib/kasa/devices.rb', line 9

def dev_name
  @dev_name
end

#ipObject (readonly)

Returns the value of attribute ip.



9
10
11
# File 'lib/kasa/devices.rb', line 9

def ip
  @ip
end

#macObject (readonly)

Returns the value of attribute mac.



9
10
11
# File 'lib/kasa/devices.rb', line 9

def mac
  @mac
end

#modelObject (readonly)

Returns the value of attribute model.



9
10
11
# File 'lib/kasa/devices.rb', line 9

def model
  @model
end

Instance Method Details

#offObject

Turn off light



31
32
33
# File 'lib/kasa/devices.rb', line 31

def off
  relay OFF
end

#off?Boolean

Is relay off?

Returns:

  • (Boolean)


36
37
38
# File 'lib/kasa/devices.rb', line 36

def off?
  relay_state.zero?
end

#onObject

Turn on light



26
27
28
# File 'lib/kasa/devices.rb', line 26

def on
  relay ON
end

#on?Boolean

Is relay on?

Returns:

  • (Boolean)


41
42
43
# File 'lib/kasa/devices.rb', line 41

def on?
  relay_state.eql? 1
end

#sysinfoObject

Get system information



21
22
23
# File 'lib/kasa/devices.rb', line 21

def sysinfo
  Kasa::Protocol.get(@ip, location: '/system/get_sysinfo')
end