Class: Sensibo::Device

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/sensibo/models/device.rb

Instance Method Summary collapse

Instance Method Details

#c_to_f(temp) ⇒ Object



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

def c_to_f(temp)
  ((temp * (9.0/5.0)) + 32).round
end

#f_to_c(temp) ⇒ Object



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

def f_to_c(temp)
  ((temp - 32) * (5.0/9.0)).round
end

#saveObject

Raises:

  • (RuntimeError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sensibo/models/device.rb', line 21

def save
  requires :identity

  temp = if self.temperature_unit == self.native_temperature_unit
           self.target_temperature
         elsif self.temperature_unit == "F"
           c_to_f(f_to_c(self.target_temperature))
         elsif self.temperature_unit == "C"
           f_to_c(c_to_f(self.target_temperature))
         end

  body = {
    "acState" => {
      "fanLevel"          => self.fan_level,
      "mode"              => self.mode,
      "on"                => self.power_on,
      "swing"             => self.swing,
      "targetTemperature" => temp,
      "temperatureUnit"   => self.temperature_unit,
    }
  }

  body = cistern.set_device_state(self.id, body)["result"]

  raise RuntimeError.new("Save Failed") unless body["status"] == "Success"
end