class Cosmos::KasaProtocol
Performs the TPLink SmartHome Protocol
Public Instance Methods
kasa_decode(string)
click to toggle source
# File targets/PLUG/lib/kasa_protocol.rb, line 30 def kasa_decode(string) key = 171 result = "" string[4..-1].each_byte do |byte| a = key ^ byte key = byte result << [a].pack("C") end return result end
kasa_encode(string)
click to toggle source
# File targets/PLUG/lib/kasa_protocol.rb, line 19 def kasa_encode(string) key = 171 result = [string.length].pack("N") string.each_byte do |byte| a = key ^ byte key = a result << a end return result end
read_data(data)
click to toggle source
Calls superclass method
# File targets/PLUG/lib/kasa_protocol.rb, line 10 def read_data(data) return super(data) if data.length <= 0 return kasa_decode(data) end
write_data(data)
click to toggle source
# File targets/PLUG/lib/kasa_protocol.rb, line 15 def write_data(data) return kasa_encode(data) end