Class: Kasa::Factory

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

Overview

Common methods across kasa devices

Class Method Summary collapse

Class Method Details

.new(ip) ⇒ Object

Factory



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kasa/factory.rb', line 27

def self.new(ip)
  sysinfo = Kasa::Protocol.get(ip, location: '/system/get_sysinfo')
  model = sysinfo['model']
  begin
    object = DEVICE_TYPES.detect { |_k, v| v.include? model }.first.allocate
  rescue StandardError => _e
    raise "#{model} not supported"
  end
  object.send :initialize, ip, sysinfo
  object
end