Class: BWA::Messages::ToggleItem

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

Constant Summary collapse

MESSAGE_TYPE =
"\x0a\xbf\x11".force_encoding(Encoding::ASCII_8BIT)
MESSAGE_LENGTH =
2

Instance Attribute Summary collapse

Attributes inherited from BWA::Message

#raw_data

Instance Method Summary collapse

Methods inherited from BWA::Message

format_duration, format_time, inherited, parse

Constructor Details

#initialize(item = nil) ⇒ ToggleItem

Returns a new instance of ToggleItem.



9
10
11
# File 'lib/bwa/messages/toggle_item.rb', line 9

def initialize(item = nil)
  self.item = item
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



7
8
9
# File 'lib/bwa/messages/toggle_item.rb', line 7

def item
  @item
end

Instance Method Details

#inspectObject



35
36
37
# File 'lib/bwa/messages/toggle_item.rb', line 35

def inspect
  "#<BWA::Messages::ToggleItem #{item}>"
end

#parse(data) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/bwa/messages/toggle_item.rb', line 13

def parse(data)
  self.item = case data[0].ord
                when 0x04; :pump1
                when 0x05; :pump2
                when 0x11; :light1
                when 0x50; :temperature_range
                when 0x51; :heating_mode
              end
end

#serializeObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bwa/messages/toggle_item.rb', line 23

def serialize
  data = "\x00\x00"
  data[0] = (case setting
               when :pump1; 0x04
               when :pump2; 0x05
               when :light1; 0x11
               when :temperature_range; 0x50
               when :heating_mode; 0x51
             end).chr
  super(data)
end