Class: Cocoro::Device

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#box_idObject

Returns the value of attribute box_id

Returns:

  • (Object)

    the current value of box_id



7
8
9
# File 'lib/cocoro/device.rb', line 7

def box_id
  @box_id
end

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



7
8
9
# File 'lib/cocoro/device.rb', line 7

def client
  @client
end

#device_idObject

Returns the value of attribute device_id

Returns:

  • (Object)

    the current value of device_id



7
8
9
# File 'lib/cocoro/device.rb', line 7

def device_id
  @device_id
end

#echonet_nodeObject

Returns the value of attribute echonet_node

Returns:

  • (Object)

    the current value of echonet_node



7
8
9
# File 'lib/cocoro/device.rb', line 7

def echonet_node
  @echonet_node
end

#echonet_objectObject

Returns the value of attribute echonet_object

Returns:

  • (Object)

    the current value of echonet_object



7
8
9
# File 'lib/cocoro/device.rb', line 7

def echonet_object
  @echonet_object
end

#makerObject

Returns the value of attribute maker

Returns:

  • (Object)

    the current value of maker



7
8
9
# File 'lib/cocoro/device.rb', line 7

def maker
  @maker
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



7
8
9
# File 'lib/cocoro/device.rb', line 7

def model
  @model
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



7
8
9
# File 'lib/cocoro/device.rb', line 7

def name
  @name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



7
8
9
# File 'lib/cocoro/device.rb', line 7

def type
  @type
end

Class Method Details

.parse_box_info(box_info, client) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cocoro/device.rb', line 19

def self.parse_box_info(box_info, client)
  box_info.flat_map do |box|
    box["echonetData"].map do |data|
      new(
        client: client,
        box_id: box["boxId"],
        device_id: data["deviceId"],
        echonet_node: data["echonetNode"],
        echonet_object: data["echonetObject"],
        name: data["labelData"]["name"],
        type: data["labelData"]["deviceType"],
        maker: data["maker"],
        model: data["model"]
      )
    end
  end
end

Instance Method Details

#fetch_status!Object



41
42
43
44
45
# File 'lib/cocoro/device.rb', line 41

def fetch_status!
  client.control_device(device: self)

  @status = client.device_status(device: self)
end

#set_air_volume!(value) ⇒ Object



56
57
58
# File 'lib/cocoro/device.rb', line 56

def set_air_volume!(value)
  send_payload!(:air_volume, value)
end

#set_humidifier_on!(value) ⇒ Object



52
53
54
# File 'lib/cocoro/device.rb', line 52

def set_humidifier_on!(value)
  send_payload!(:humidifier_on, value)
end

#set_power_on!(value) ⇒ Object

rubocop:disable Naming/AccessorMethodName



48
49
50
# File 'lib/cocoro/device.rb', line 48

def set_power_on!(value)
  send_payload!(:power_on, value)
end

#statusObject



37
38
39
# File 'lib/cocoro/device.rb', line 37

def status
  @status || fetch_status!
end