Class: SDN::CLI::MQTT::Motor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMotor



58
59
60
61
62
# File 'lib/sdn/cli/mqtt/motor.rb', line 58

def initialize(*)
  members.each { |k| self[k] = :nil }
  @groups = [].fill(nil, 0, 16)
  super
end

Instance Attribute Details

#addrObject

Returns the value of attribute addr



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

def addr
  @addr
end

#bridgeObject

Returns the value of attribute bridge



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

def bridge
  @bridge
end

#directionObject

Returns the value of attribute direction



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

def direction
  @direction
end

#down_limitObject

Returns the value of attribute down_limit



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

def down_limit
  @down_limit
end

#down_speedObject

Returns the value of attribute down_speed



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

def down_speed
  @down_speed
end

#groupsObject

Returns the value of attribute groups



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

def groups
  @groups
end

#ipObject

Returns the value of attribute ip



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

def ip
  @ip
end

#ip10_percentObject

Returns the value of attribute ip10_percent



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

def ip10_percent
  @ip10_percent
end

#ip10_pulsesObject

Returns the value of attribute ip10_pulses



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

def ip10_pulses
  @ip10_pulses
end

#ip11_percentObject

Returns the value of attribute ip11_percent



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

def ip11_percent
  @ip11_percent
end

#ip11_pulsesObject

Returns the value of attribute ip11_pulses



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

def ip11_pulses
  @ip11_pulses
end

#ip12_percentObject

Returns the value of attribute ip12_percent



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

def ip12_percent
  @ip12_percent
end

#ip12_pulsesObject

Returns the value of attribute ip12_pulses



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

def ip12_pulses
  @ip12_pulses
end

#ip13_percentObject

Returns the value of attribute ip13_percent



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

def ip13_percent
  @ip13_percent
end

#ip13_pulsesObject

Returns the value of attribute ip13_pulses



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

def ip13_pulses
  @ip13_pulses
end

#ip14_percentObject

Returns the value of attribute ip14_percent



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

def ip14_percent
  @ip14_percent
end

#ip14_pulsesObject

Returns the value of attribute ip14_pulses



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

def ip14_pulses
  @ip14_pulses
end

#ip15_percentObject

Returns the value of attribute ip15_percent



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

def ip15_percent
  @ip15_percent
end

#ip15_pulsesObject

Returns the value of attribute ip15_pulses



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

def ip15_pulses
  @ip15_pulses
end

#ip16_percentObject

Returns the value of attribute ip16_percent



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

def ip16_percent
  @ip16_percent
end

#ip16_pulsesObject

Returns the value of attribute ip16_pulses



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

def ip16_pulses
  @ip16_pulses
end

#ip1_percentObject

Returns the value of attribute ip1_percent



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

def ip1_percent
  @ip1_percent
end

#ip1_pulsesObject

Returns the value of attribute ip1_pulses



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

def ip1_pulses
  @ip1_pulses
end

#ip2_percentObject

Returns the value of attribute ip2_percent



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

def ip2_percent
  @ip2_percent
end

#ip2_pulsesObject

Returns the value of attribute ip2_pulses



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

def ip2_pulses
  @ip2_pulses
end

#ip3_percentObject

Returns the value of attribute ip3_percent



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

def ip3_percent
  @ip3_percent
end

#ip3_pulsesObject

Returns the value of attribute ip3_pulses



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

def ip3_pulses
  @ip3_pulses
end

#ip4_percentObject

Returns the value of attribute ip4_percent



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

def ip4_percent
  @ip4_percent
end

#ip4_pulsesObject

Returns the value of attribute ip4_pulses



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

def ip4_pulses
  @ip4_pulses
end

#ip5_percentObject

Returns the value of attribute ip5_percent



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

def ip5_percent
  @ip5_percent
end

#ip5_pulsesObject

Returns the value of attribute ip5_pulses



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

def ip5_pulses
  @ip5_pulses
end

#ip6_percentObject

Returns the value of attribute ip6_percent



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

def ip6_percent
  @ip6_percent
end

#ip6_pulsesObject

Returns the value of attribute ip6_pulses



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

def ip6_pulses
  @ip6_pulses
end

#ip7_percentObject

Returns the value of attribute ip7_percent



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

def ip7_percent
  @ip7_percent
end

#ip7_pulsesObject

Returns the value of attribute ip7_pulses



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

def ip7_pulses
  @ip7_pulses
end

#ip8_percentObject

Returns the value of attribute ip8_percent



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

def ip8_percent
  @ip8_percent
end

#ip8_pulsesObject

Returns the value of attribute ip8_pulses



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

def ip8_pulses
  @ip8_pulses
end

#ip9_percentObject

Returns the value of attribute ip9_percent



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

def ip9_percent
  @ip9_percent
end

#ip9_pulsesObject

Returns the value of attribute ip9_pulses



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

def ip9_pulses
  @ip9_pulses
end

#labelObject

Returns the value of attribute label



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

def label
  @label
end

#last_actionObject

Returns the value of attribute last_action



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

def last_action
  @last_action
end

#last_action_causeObject

Returns the value of attribute last_action_cause



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

def last_action_cause
  @last_action_cause
end

#last_action_sourceObject

Returns the value of attribute last_action_source



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

def last_action_source
  @last_action_source
end

#last_directionObject

Returns the value of attribute last_direction



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

def last_direction
  @last_direction
end

#last_position_pulsesObject

Returns the value of attribute last_position_pulses



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

def last_position_pulses
  @last_position_pulses
end

#node_typeObject

Returns the value of attribute node_type



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

def node_type
  @node_type
end

#position_percentObject

Returns the value of attribute position_percent



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

def position_percent
  @position_percent
end

#position_pulsesObject

Returns the value of attribute position_pulses



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

def position_pulses
  @position_pulses
end

#slow_speedObject

Returns the value of attribute slow_speed



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

def slow_speed
  @slow_speed
end

#stateObject

Returns the value of attribute state



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

def state
  @state
end

#up_limitObject

Returns the value of attribute up_limit



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

def up_limit
  @up_limit
end

#up_speedObject

Returns the value of attribute up_speed



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

def up_speed
  @up_speed
end

Instance Method Details

#add_group(index, address) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/sdn/cli/mqtt/motor.rb', line 71

def add_group(index, address)
  group = bridge.add_group(Message.print_address(address)) if address
  old_group = @groups[index - 1]
  @groups[index - 1] = address
  group&.publish(:motors, group.motors_string)
  publish(:groups, groups_string)
  bridge.touch_group(old_group) if old_group
end

#group_objectsObject



102
103
104
# File 'lib/sdn/cli/mqtt/motor.rb', line 102

def group_objects
  groups_string.split(",").map { |addr| bridge.groups[addr.delete(".")] }
end

#groups_stringObject



98
99
100
# File 'lib/sdn/cli/mqtt/motor.rb', line 98

def groups_string
  @groups.compact.map { |g| Message.print_address(g) }.sort.uniq.join(",")
end

#publish(attribute, value) ⇒ Object



64
65
66
67
68
69
# File 'lib/sdn/cli/mqtt/motor.rb', line 64

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

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

#set_groups(groups) ⇒ Object

rubocop:disable Naming/AccessorMethodName



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/sdn/cli/mqtt/motor.rb', line 80

def set_groups(groups) # rubocop:disable Naming/AccessorMethodName
  return unless /^(?:\h{2}[:.]?\h{2}[:.]?\h{2}(?:,\h{2}[:.]?\h{2}[:.]?\h{2})*)?$/i.match?(groups)

  groups = groups.split(",").sort.uniq.map do |g|
             Message.parse_address(g)
           end.select { |g| Message.group_address?(g) }
  groups.fill(nil, groups.length, 16 - groups.length)
  messages = []
  sdn_addr = Message.parse_address(addr)
  groups.each_with_index do |g, i|
    if @groups[i] != g
      messages << Message::SetGroupAddr.new(sdn_addr, i + 1, g).tap { |m| m.ack_requested = true }
      messages << Message::GetGroupAddr.new(sdn_addr, i + 1)
    end
  end
  messages
end