Class: BWA::Messages::Status

Inherits:
BWA::Message show all
Defined in:
lib/bwa/messages/status.rb

Constant Summary collapse

MESSAGE_TYPE =
"\xaf\x13".b
MESSAGE_LENGTH =

additional features have been added in later versions

(24..32).freeze
NOTIFICATIONS =
{
  0x00 => nil,
  0x0a => :ph,
  0x04 => :filter,
  0x09 => :sanitizer
}.freeze

Instance Attribute Summary collapse

Attributes inherited from BWA::Message

#raw_data, #src

Instance Method Summary collapse

Methods inherited from BWA::Message

format_duration, format_time, inherited, parse

Constructor Details

#initializeStatus

Returns a new instance of Status.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bwa/messages/status.rb', line 41

def initialize
  super

  @src = 0xff
  self.hold = false
  self.priming = false
  self.notification = nil
  self.heating_mode = :ready
  @temperature_scale = :fahrenheit
  self.twenty_four_hour_time = false
  self.filter_cycles = Array.new(2, false)
  self.heating = false
  self.temperature_range = :high
  self.hour = self.minute = 0
  self.circulation_pump = false
  self.pumps = Array.new(6, 0)
  self.lights = Array.new(2, false)
  self.mister = false
  self.aux = Array.new(2, false)
  self.target_temperature = 100
end

Instance Attribute Details

#auxObject

Returns the value of attribute aux.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def aux
  @aux
end

#blowerObject

Returns the value of attribute blower.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def blower
  @blower
end

#circulation_pumpObject

Returns the value of attribute circulation_pump.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def circulation_pump
  @circulation_pump
end

#current_temperatureObject

Returns the value of attribute current_temperature.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def current_temperature
  @current_temperature
end

#filter_cyclesObject

Returns the value of attribute filter_cycles.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def filter_cycles
  @filter_cycles
end

#heatingObject Also known as: heating?

Returns the value of attribute heating.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def heating
  @heating
end

#heating_modeObject

Returns the value of attribute heating_mode.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def heating_mode
  @heating_mode
end

#holdObject Also known as: hold?

Returns the value of attribute hold.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def hold
  @hold
end

#hourObject

Returns the value of attribute hour.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def hour
  @hour
end

#lightsObject

Returns the value of attribute lights.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def lights
  @lights
end

#minuteObject

Returns the value of attribute minute.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def minute
  @minute
end

#misterObject

Returns the value of attribute mister.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def mister
  @mister
end

#notificationObject

Returns the value of attribute notification.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def notification
  @notification
end

#primingObject Also known as: priming?

Returns the value of attribute priming.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def priming
  @priming
end

#pumpsObject

Returns the value of attribute pumps.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def pumps
  @pumps
end

#target_temperatureObject

Returns the value of attribute target_temperature.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def target_temperature
  @target_temperature
end

#temperature_rangeObject

Returns the value of attribute temperature_range.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def temperature_range
  @temperature_range
end

#temperature_scaleObject

Returns the value of attribute temperature_scale.



24
25
26
# File 'lib/bwa/messages/status.rb', line 24

def temperature_scale
  @temperature_scale
end

#twenty_four_hour_timeObject Also known as: twenty_four_hour_time?

Returns the value of attribute twenty_four_hour_time.



6
7
8
# File 'lib/bwa/messages/status.rb', line 6

def twenty_four_hour_time
  @twenty_four_hour_time
end

Instance Method Details

#inspectObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/bwa/messages/status.rb', line 188

def inspect
  items = []

  items << "hold" if hold
  items << "priming" if priming
  items << "notification=#{notification}" if notification
  items << self.class.format_time(hour, minute, twenty_four_hour_time: twenty_four_hour_time)
  items << "#{current_temperature || "--"}/#{target_temperature}°#{temperature_scale.to_s[0].upcase}"
  items << "filter_cycles=#{filter_cycles.inspect}"
  items << heating_mode
  items << "heating" if heating
  items << temperature_range
  items << "circulation_pump" if circulation_pump
  items << "blower=#{blower}"
  items << "pumps=#{pumps.inspect}"
  items << "lights=#{lights.inspect}"
  items << "aux=#{aux.inspect}"
  items << "mister" if mister

  "#<BWA::Messages::Status #{items.join(" ")}>"
end

#log?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bwa/messages/status.rb', line 63

def log?
  BWA.verbosity >= 1
end

#parse(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/bwa/messages/status.rb', line 67

def parse(data)
  flags = data[0].ord
  self.hold = (flags & 0x05 != 0)

  self.priming = data[1].ord == 0x01
  flags = data[5].ord
  self.heating_mode = case flags & 0x03
                      when 0x00 then :ready
                      when 0x01 then :rest
                      when 0x02 then :ready_in_rest
                      end
  self.notification = data[1].ord == 0x03 && NOTIFICATIONS[data[6].ord]
  flags = data[9].ord
  self.temperature_scale = (flags & 0x01 == 0x01) ? :celsius : :fahrenheit
  self.twenty_four_hour_time = (flags & 0x02 == 0x02)
  filter_cycles[0] = (flags & 0x04 != 0)
  filter_cycles[1] = (flags & 0x08 != 0)
  flags = data[10].ord
  self.heating = (flags & 0x30 != 0)
  self.temperature_range = (flags & 0x04 == 0x04) ? :high : :low
  flags = data[11].ord
  pumps[0] = flags & 0x03
  pumps[1] = (flags >> 2) & 0x03
  pumps[2] = (flags >> 4) & 0x03
  pumps[3] = (flags >> 6) & 0x03
  flags = data[12].ord
  pumps[4] = flags & 0x03
  pumps[5] = (flags >> 2) & 0x03

  flags = data[13].ord
  self.circulation_pump = (flags & 0x02 == 0x02)
  self.blower = (flags >> 2) & 0x03
  flags = data[14].ord
  lights[0] = (flags & 0x03 != 0)
  lights[1] = ((flags >> 2) & 0x03 != 0)
  flags = data[15].ord
  self.mister = (flags & 0x01 == 0x01)
  aux[0] = (flags & 0x08 != 0)
  aux[1] = (flags & 0x10 != 0)
  self.hour = data[3].ord
  self.minute = data[4].ord
  self.current_temperature = data[2].ord
  self.current_temperature = nil if current_temperature == 0xff
  self.target_temperature = data[20].ord

  return unless temperature_scale == :celsius

  self.current_temperature /= 2.0 if current_temperature
  self.target_temperature /= 2.0 if target_temperature
end

#serializeObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/bwa/messages/status.rb', line 118

def serialize
  data = "\x00" * 24
  data[0] = (hold ? 0x05 : 0x00).chr
  data[1] = if priming
              0x01
            elsif notification
              0x04
            else
              0x00
            end.chr
  data[5] = { ready: 0x00,
              rest: 0x01,
              ready_in_rest: 0x02 }[heating_mode].chr
  data[6] = NOTIFICATIONS.invert[notification].chr
  flags = 0
  flags |= 0x01 if temperature_scale == :celsius
  flags |= 0x02 if twenty_four_hour_time
  data[9] = flags.chr
  flags = 0
  flags |= 0x30 if heating
  flags |= 0x04 if temperature_range == :high
  data[10] = flags.chr
  flags = 0
  flags |= pump1
  flags |= pump2 * 4
  data[11] = flags.chr
  flags = 0
  flags |= 0x02 if circulation_pump
  data[13] = flags.chr
  flags = 0
  flags |= 0x03 if light1
  data[14] = flags.chr
  data[3] = hour.chr
  data[4] = minute.chr
  if temperature_scale == :celsius
    data[2] = (current_temperature ? (current_temperature * 2).to_i : 0xff).chr
    data[20] = (target_temperature * 2).to_i.chr
  else
    data[2] = (current_temperature.to_i || 0xff).chr
    data[20] = target_temperature.to_i.chr
  end

  super(data)
end