Class: TuyaCloud::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya_cloud/device.rb

Defined Under Namespace

Classes: ColorLight, Control, Light, Scene, Switch, Switchable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, auth_context) ⇒ Device

Returns a new instance of Device.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tuya_cloud/device.rb', line 10

def initialize(json, auth_context)
  self.id   = json['id']
  self.name = json['name']
  self.type = json['dev_type']
  case type
  when 'light'
    self.controls = if json['data'] && json['data']['color_mode']
                      ColorLight.new(json, auth_context)
                    else
                      Light.new(json, auth_context)
                    end
  when 'switch'
    self.controls = Switch.new(json, auth_context)
  when 'scene'
    self.controls = Scene.new(json, auth_context)
  else
    raise ArgumentError, 'unknown device type'

  end
end

Instance Attribute Details

#controlsObject

Returns the value of attribute controls.



5
6
7
# File 'lib/tuya_cloud/device.rb', line 5

def controls
  @controls
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tuya_cloud/device.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tuya_cloud/device.rb', line 5

def name
  @name
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/tuya_cloud/device.rb', line 5

def type
  @type
end