Class: MideaAirCondition::Device

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

Overview

Device representation (now only for status parsing)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Device

Returns a new instance of Device.



8
9
10
11
# File 'lib/device.rb', line 8

def initialize(data)
  @data = data
  @pointer = 0x33
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#ecoObject



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

def eco
  !((@data[@pointer + 8] & 0x10) >> 4).zero?
end

#fan_speedObject



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

def fan_speed
  @data[@pointer + 2] & 0x7f
end

#indoor_temperatureObject



40
41
42
# File 'lib/device.rb', line 40

def indoor_temperature
  (@data[@pointer + 10] - 50) / 2
end

#modeObject



21
22
23
# File 'lib/device.rb', line 21

def mode
  (@data[@pointer + 1] & 0xe0) >> 5
end

#mode_humanObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/device.rb', line 25

def mode_human
  mode_value = 'unknown'
  mode_value = 'auto' if mode == 1
  mode_value = 'cool' if mode == 2
  mode_value = 'dry' if mode == 3
  mode_value = 'heat' if mode == 4
  mode_value = 'fan' if mode == 5

  mode_value
end

#off_timerObject



61
62
63
64
65
66
67
68
# File 'lib/device.rb', line 61

def off_timer
  value = @data[@pointer + 4]
  {
    status:  !((value & 0x80) >> 7).zero?,
    hour:    ((value & 0x7c) >> 2),
    minutes: ((value & 0x3) | ((value & 0xf0)))
  }
end

#off_timer_humanObject



74
75
76
# File 'lib/device.rb', line 74

def off_timer_human
  "#{off_timer[:hours]}:#{off_timer[:mins]}"
end

#on_timerObject



52
53
54
55
56
57
58
59
# File 'lib/device.rb', line 52

def on_timer
  value = @data[@pointer + 3]
  {
    status:  !((value & 0x80) >> 7).zero?,
    hour:    ((value & 0x7c) >> 2),
    minutes: ((value & 0x3) | ((value & 0xf0)))
  }
end

#on_timer_humanObject



70
71
72
# File 'lib/device.rb', line 70

def on_timer_human
  "#{on_timer[:hours]}:#{on_timer[:mins]}"
end

#outdoor_temperatureObject



44
45
46
# File 'lib/device.rb', line 44

def outdoor_temperature
  (@data[@pointer + 11] - 50) / 2
end

#power_statusObject



13
14
15
# File 'lib/device.rb', line 13

def power_status
  !(@data[@pointer] & 0x01).zero?
end

#temperatureObject



17
18
19
# File 'lib/device.rb', line 17

def temperature
  (@data[@pointer + 1] & 0xf) + 16
end