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

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

Overview

In-memory state container for a discovered motor and its published MQTT attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMotor

Returns a new instance of Motor.



61
62
63
64
65
66
67
# File 'lib/sdn/cli/mqtt/motor.rb', line 61

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

Instance Attribute Details

#addrObject

Returns the value of attribute addr

Returns:

  • (Object)

    the current value of addr



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

def addr
  @addr
end

#bridgeObject

Returns the value of attribute bridge

Returns:

  • (Object)

    the current value of bridge



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

def bridge
  @bridge
end

#directionObject

Returns the value of attribute direction

Returns:

  • (Object)

    the current value of direction



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

def direction
  @direction
end

#down_limitObject

Returns the value of attribute down_limit

Returns:

  • (Object)

    the current value of down_limit



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

def down_limit
  @down_limit
end

#down_speedObject

Returns the value of attribute down_speed

Returns:

  • (Object)

    the current value of down_speed



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

def down_speed
  @down_speed
end

#group_objects<SDN::CLI::MQTT::Group> (readonly)

Returns:



127
128
129
# File 'lib/sdn/cli/mqtt/motor.rb', line 127

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

#groupsObject

Returns the value of attribute groups

Returns:

  • (Object)

    the current value of groups



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

def groups
  @groups
end

#groups_stringString (readonly)

Returns the current group membership list as a normalized string.

Returns:

  • (String)


120
121
122
# File 'lib/sdn/cli/mqtt/motor.rb', line 120

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

#hass_stateObject

Returns the value of attribute hass_state

Returns:

  • (Object)

    the current value of hass_state



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

def hass_state
  @hass_state
end

#ipObject

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



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

def ip
  @ip
end

#ip10_percentObject

Returns the value of attribute ip10_percent

Returns:

  • (Object)

    the current value of ip10_percent



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

def ip10_percent
  @ip10_percent
end

#ip10_pulsesObject

Returns the value of attribute ip10_pulses

Returns:

  • (Object)

    the current value of ip10_pulses



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

def ip10_pulses
  @ip10_pulses
end

#ip11_percentObject

Returns the value of attribute ip11_percent

Returns:

  • (Object)

    the current value of ip11_percent



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

def ip11_percent
  @ip11_percent
end

#ip11_pulsesObject

Returns the value of attribute ip11_pulses

Returns:

  • (Object)

    the current value of ip11_pulses



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

def ip11_pulses
  @ip11_pulses
end

#ip12_percentObject

Returns the value of attribute ip12_percent

Returns:

  • (Object)

    the current value of ip12_percent



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

def ip12_percent
  @ip12_percent
end

#ip12_pulsesObject

Returns the value of attribute ip12_pulses

Returns:

  • (Object)

    the current value of ip12_pulses



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

def ip12_pulses
  @ip12_pulses
end

#ip13_percentObject

Returns the value of attribute ip13_percent

Returns:

  • (Object)

    the current value of ip13_percent



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

def ip13_percent
  @ip13_percent
end

#ip13_pulsesObject

Returns the value of attribute ip13_pulses

Returns:

  • (Object)

    the current value of ip13_pulses



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

def ip13_pulses
  @ip13_pulses
end

#ip14_percentObject

Returns the value of attribute ip14_percent

Returns:

  • (Object)

    the current value of ip14_percent



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

def ip14_percent
  @ip14_percent
end

#ip14_pulsesObject

Returns the value of attribute ip14_pulses

Returns:

  • (Object)

    the current value of ip14_pulses



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

def ip14_pulses
  @ip14_pulses
end

#ip15_percentObject

Returns the value of attribute ip15_percent

Returns:

  • (Object)

    the current value of ip15_percent



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

def ip15_percent
  @ip15_percent
end

#ip15_pulsesObject

Returns the value of attribute ip15_pulses

Returns:

  • (Object)

    the current value of ip15_pulses



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

def ip15_pulses
  @ip15_pulses
end

#ip16_percentObject

Returns the value of attribute ip16_percent

Returns:

  • (Object)

    the current value of ip16_percent



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

def ip16_percent
  @ip16_percent
end

#ip16_pulsesObject

Returns the value of attribute ip16_pulses

Returns:

  • (Object)

    the current value of ip16_pulses



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

def ip16_pulses
  @ip16_pulses
end

#ip1_percentObject

Returns the value of attribute ip1_percent

Returns:

  • (Object)

    the current value of ip1_percent



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

def ip1_percent
  @ip1_percent
end

#ip1_pulsesObject

Returns the value of attribute ip1_pulses

Returns:

  • (Object)

    the current value of ip1_pulses



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

def ip1_pulses
  @ip1_pulses
end

#ip2_percentObject

Returns the value of attribute ip2_percent

Returns:

  • (Object)

    the current value of ip2_percent



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

def ip2_percent
  @ip2_percent
end

#ip2_pulsesObject

Returns the value of attribute ip2_pulses

Returns:

  • (Object)

    the current value of ip2_pulses



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

def ip2_pulses
  @ip2_pulses
end

#ip3_percentObject

Returns the value of attribute ip3_percent

Returns:

  • (Object)

    the current value of ip3_percent



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

def ip3_percent
  @ip3_percent
end

#ip3_pulsesObject

Returns the value of attribute ip3_pulses

Returns:

  • (Object)

    the current value of ip3_pulses



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

def ip3_pulses
  @ip3_pulses
end

#ip4_percentObject

Returns the value of attribute ip4_percent

Returns:

  • (Object)

    the current value of ip4_percent



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

def ip4_percent
  @ip4_percent
end

#ip4_pulsesObject

Returns the value of attribute ip4_pulses

Returns:

  • (Object)

    the current value of ip4_pulses



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

def ip4_pulses
  @ip4_pulses
end

#ip5_percentObject

Returns the value of attribute ip5_percent

Returns:

  • (Object)

    the current value of ip5_percent



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

def ip5_percent
  @ip5_percent
end

#ip5_pulsesObject

Returns the value of attribute ip5_pulses

Returns:

  • (Object)

    the current value of ip5_pulses



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

def ip5_pulses
  @ip5_pulses
end

#ip6_percentObject

Returns the value of attribute ip6_percent

Returns:

  • (Object)

    the current value of ip6_percent



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

def ip6_percent
  @ip6_percent
end

#ip6_pulsesObject

Returns the value of attribute ip6_pulses

Returns:

  • (Object)

    the current value of ip6_pulses



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

def ip6_pulses
  @ip6_pulses
end

#ip7_percentObject

Returns the value of attribute ip7_percent

Returns:

  • (Object)

    the current value of ip7_percent



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

def ip7_percent
  @ip7_percent
end

#ip7_pulsesObject

Returns the value of attribute ip7_pulses

Returns:

  • (Object)

    the current value of ip7_pulses



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

def ip7_pulses
  @ip7_pulses
end

#ip8_percentObject

Returns the value of attribute ip8_percent

Returns:

  • (Object)

    the current value of ip8_percent



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

def ip8_percent
  @ip8_percent
end

#ip8_pulsesObject

Returns the value of attribute ip8_pulses

Returns:

  • (Object)

    the current value of ip8_pulses



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

def ip8_pulses
  @ip8_pulses
end

#ip9_percentObject

Returns the value of attribute ip9_percent

Returns:

  • (Object)

    the current value of ip9_percent



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

def ip9_percent
  @ip9_percent
end

#ip9_pulsesObject

Returns the value of attribute ip9_pulses

Returns:

  • (Object)

    the current value of ip9_pulses



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

def ip9_pulses
  @ip9_pulses
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



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

def label
  @label
end

#last_actionObject

Returns the value of attribute last_action

Returns:

  • (Object)

    the current value of last_action



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

def last_action
  @last_action
end

#last_action_causeObject

Returns the value of attribute last_action_cause

Returns:

  • (Object)

    the current value of last_action_cause



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

def last_action_cause
  @last_action_cause
end

#last_action_retriesObject

Returns the value of attribute last_action_retries

Returns:

  • (Object)

    the current value of last_action_retries



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

def last_action_retries
  @last_action_retries
end

#last_action_sourceObject

Returns the value of attribute last_action_source

Returns:

  • (Object)

    the current value of last_action_source



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

def last_action_source
  @last_action_source
end

#last_directionObject

Returns the value of attribute last_direction

Returns:

  • (Object)

    the current value of last_direction



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

def last_direction
  @last_direction
end

#last_position_pulsesObject

Returns the value of attribute last_position_pulses

Returns:

  • (Object)

    the current value of last_position_pulses



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

def last_position_pulses
  @last_position_pulses
end

#node_typeObject

Returns the value of attribute node_type

Returns:

  • (Object)

    the current value of node_type



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

def node_type
  @node_type
end

#position_percentObject

Returns the value of attribute position_percent

Returns:

  • (Object)

    the current value of position_percent



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

def position_percent
  @position_percent
end

#position_pulsesObject

Returns the value of attribute position_pulses

Returns:

  • (Object)

    the current value of position_pulses



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

def position_pulses
  @position_pulses
end

#slow_speedObject

Returns the value of attribute slow_speed

Returns:

  • (Object)

    the current value of slow_speed



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

def slow_speed
  @slow_speed
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



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

def state
  @state
end

#up_limitObject

Returns the value of attribute up_limit

Returns:

  • (Object)

    the current value of up_limit



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

def up_limit
  @up_limit
end

#up_speedObject

Returns the value of attribute up_speed

Returns:

  • (Object)

    the current value of up_speed



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

def up_speed
  @up_speed
end

Instance Method Details

#add_group(index, address) ⇒ void

This method returns an undefined value.

Updates a group slot and refreshes derived group membership state.

Parameters:

  • index (Integer)

    group slot number

  • address ((Integer, Integer, Integer), nil)

    group address



83
84
85
86
87
88
89
90
# File 'lib/sdn/cli/mqtt/motor.rb', line 83

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

#set_groups(groups) ⇒ <SDN::Message>

Builds the SDN writes needed to reconcile group membership with a comma-separated list.

Parameters:

  • groups (String)

    comma-separated group addresses

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/sdn/cli/mqtt/motor.rb', line 97

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