Class: BWA::Messages::ToggleItem

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

Constant Summary collapse

MESSAGE_TYPE =
"\xbf\x11".b
MESSAGE_LENGTH =
2
ITEMS =
{
  normal_operation: 0x01,
  clear_notification: 0x03,
  pump1: 0x04,
  pump2: 0x05,
  pump3: 0x06,
  pump4: 0x07,
  pump5: 0x08,
  pump6: 0x09,
  blower: 0x0c,
  mister: 0x0e,
  light1: 0x11,
  light2: 0x12,
  aux1: 0x16,
  aux2: 0x17,
  soak: 0x1d,
  hold: 0x3c,
  temperature_range: 0x50,
  heating_mode: 0x51
}.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

#initialize(item = nil) ⇒ ToggleItem

Returns a new instance of ToggleItem.



31
32
33
34
# File 'lib/bwa/messages/toggle_item.rb', line 31

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

Instance Attribute Details

#itemObject

Returns the value of attribute item.



29
30
31
# File 'lib/bwa/messages/toggle_item.rb', line 29

def item
  @item
end

Instance Method Details

#inspectObject



59
60
61
# File 'lib/bwa/messages/toggle_item.rb', line 59

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

#log?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/bwa/messages/toggle_item.rb', line 36

def log?
  return true if BWA.verbosity >= 2
  # dunno why we receive this, but somebody is spamming the bus
  # trying to toggle an item we don't know
  return false if item == 0 # rubocop:disable Style/NumericPredicate could be a symbol

  true
end

#parse(data) ⇒ Object



45
46
47
# File 'lib/bwa/messages/toggle_item.rb', line 45

def parse(data)
  self.item = ITEMS.invert[data[0].ord] || data[0].ord
end

#serializeObject



49
50
51
52
53
54
55
56
57
# File 'lib/bwa/messages/toggle_item.rb', line 49

def serialize
  data = +"\x00\x00"
  data[0] = if item.is_a?(Integer)
              item.chr
            else
              ITEMS[item].chr
            end
  super(data)
end