Class: SDN::CLI::MQTT::Group

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdn/cli/mqtt/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGroup

Returns a new instance of Group.



7
8
9
10
# File 'lib/sdn/cli/mqtt/group.rb', line 7

def initialize(*)
  members.each { |k| self[k] = :nil }
  super
end

Instance Attribute Details

#addrObject

Returns the value of attribute addr

Returns:

  • (Object)

    the current value of addr



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def addr
  @addr
end

#bridgeObject

Returns the value of attribute bridge

Returns:

  • (Object)

    the current value of bridge



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def bridge
  @bridge
end

#ipObject

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def ip
  @ip
end

#last_directionObject

Returns the value of attribute last_direction

Returns:

  • (Object)

    the current value of last_direction



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def last_direction
  @last_direction
end

#motorsObject

Returns the value of attribute motors

Returns:

  • (Object)

    the current value of motors



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def motors
  @motors
end

#position_percentObject

Returns the value of attribute position_percent

Returns:

  • (Object)

    the current value of position_percent



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def position_percent
  @position_percent
end

#position_pulsesObject

Returns the value of attribute position_pulses

Returns:

  • (Object)

    the current value of position_pulses



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def position_pulses
  @position_pulses
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



6
7
8
# File 'lib/sdn/cli/mqtt/group.rb', line 6

def state
  @state
end

Instance Method Details

#motor_objectsObject



23
24
25
# File 'lib/sdn/cli/mqtt/group.rb', line 23

def motor_objects
  bridge.motors.select { |_addr, motor| motor.groups_string.include?(printed_addr) }.values
end

#motors_stringObject



27
28
29
# File 'lib/sdn/cli/mqtt/group.rb', line 27

def motors_string
  motor_objects.map { |m| Message.print_address(Message.parse_address(m.addr)) }.sort.join(",")
end

#printed_addrObject



19
20
21
# File 'lib/sdn/cli/mqtt/group.rb', line 19

def printed_addr
  Message.print_address(Message.parse_address(addr))
end

#publish(attribute, value) ⇒ Object



12
13
14
15
16
17
# File 'lib/sdn/cli/mqtt/group.rb', line 12

def publish(attribute, value)
  return unless self[attribute] != value

  bridge.publish("#{addr}/#{attribute.to_s.tr("_", "-")}", value.to_s)
  self[attribute] = value
end