Class: SDN::Motor

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdn/mqtt_bridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMotor

Returns a new instance of Motor.



55
56
57
58
59
# File 'lib/sdn/mqtt_bridge.rb', line 55

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

Returns:

  • (Object)

    the current value of addr



6
7
8
# File 'lib/sdn/mqtt_bridge.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/mqtt_bridge.rb', line 6

def bridge
  @bridge
end

#directionObject

Returns the value of attribute direction

Returns:

  • (Object)

    the current value of direction



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def direction
  @direction
end

#downlimitObject

Returns the value of attribute downlimit

Returns:

  • (Object)

    the current value of downlimit



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def downlimit
  @downlimit
end

#downspeedObject

Returns the value of attribute downspeed

Returns:

  • (Object)

    the current value of downspeed



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def downspeed
  @downspeed
end

#groupsObject

Returns the value of attribute groups

Returns:

  • (Object)

    the current value of groups



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def groups
  @groups
end

#ipObject

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip
  @ip
end

#ip10percentObject

Returns the value of attribute ip10percent

Returns:

  • (Object)

    the current value of ip10percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip10percent
  @ip10percent
end

#ip10pulsesObject

Returns the value of attribute ip10pulses

Returns:

  • (Object)

    the current value of ip10pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip10pulses
  @ip10pulses
end

#ip11percentObject

Returns the value of attribute ip11percent

Returns:

  • (Object)

    the current value of ip11percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip11percent
  @ip11percent
end

#ip11pulsesObject

Returns the value of attribute ip11pulses

Returns:

  • (Object)

    the current value of ip11pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip11pulses
  @ip11pulses
end

#ip12percentObject

Returns the value of attribute ip12percent

Returns:

  • (Object)

    the current value of ip12percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip12percent
  @ip12percent
end

#ip12pulsesObject

Returns the value of attribute ip12pulses

Returns:

  • (Object)

    the current value of ip12pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip12pulses
  @ip12pulses
end

#ip13percentObject

Returns the value of attribute ip13percent

Returns:

  • (Object)

    the current value of ip13percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip13percent
  @ip13percent
end

#ip13pulsesObject

Returns the value of attribute ip13pulses

Returns:

  • (Object)

    the current value of ip13pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip13pulses
  @ip13pulses
end

#ip14percentObject

Returns the value of attribute ip14percent

Returns:

  • (Object)

    the current value of ip14percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip14percent
  @ip14percent
end

#ip14pulsesObject

Returns the value of attribute ip14pulses

Returns:

  • (Object)

    the current value of ip14pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip14pulses
  @ip14pulses
end

#ip15percentObject

Returns the value of attribute ip15percent

Returns:

  • (Object)

    the current value of ip15percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip15percent
  @ip15percent
end

#ip15pulsesObject

Returns the value of attribute ip15pulses

Returns:

  • (Object)

    the current value of ip15pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip15pulses
  @ip15pulses
end

#ip16percentObject

Returns the value of attribute ip16percent

Returns:

  • (Object)

    the current value of ip16percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip16percent
  @ip16percent
end

#ip16pulsesObject

Returns the value of attribute ip16pulses

Returns:

  • (Object)

    the current value of ip16pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip16pulses
  @ip16pulses
end

#ip1percentObject

Returns the value of attribute ip1percent

Returns:

  • (Object)

    the current value of ip1percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip1percent
  @ip1percent
end

#ip1pulsesObject

Returns the value of attribute ip1pulses

Returns:

  • (Object)

    the current value of ip1pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip1pulses
  @ip1pulses
end

#ip2percentObject

Returns the value of attribute ip2percent

Returns:

  • (Object)

    the current value of ip2percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip2percent
  @ip2percent
end

#ip2pulsesObject

Returns the value of attribute ip2pulses

Returns:

  • (Object)

    the current value of ip2pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip2pulses
  @ip2pulses
end

#ip3percentObject

Returns the value of attribute ip3percent

Returns:

  • (Object)

    the current value of ip3percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip3percent
  @ip3percent
end

#ip3pulsesObject

Returns the value of attribute ip3pulses

Returns:

  • (Object)

    the current value of ip3pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip3pulses
  @ip3pulses
end

#ip4percentObject

Returns the value of attribute ip4percent

Returns:

  • (Object)

    the current value of ip4percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip4percent
  @ip4percent
end

#ip4pulsesObject

Returns the value of attribute ip4pulses

Returns:

  • (Object)

    the current value of ip4pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip4pulses
  @ip4pulses
end

#ip5percentObject

Returns the value of attribute ip5percent

Returns:

  • (Object)

    the current value of ip5percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip5percent
  @ip5percent
end

#ip5pulsesObject

Returns the value of attribute ip5pulses

Returns:

  • (Object)

    the current value of ip5pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip5pulses
  @ip5pulses
end

#ip6percentObject

Returns the value of attribute ip6percent

Returns:

  • (Object)

    the current value of ip6percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip6percent
  @ip6percent
end

#ip6pulsesObject

Returns the value of attribute ip6pulses

Returns:

  • (Object)

    the current value of ip6pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip6pulses
  @ip6pulses
end

#ip7percentObject

Returns the value of attribute ip7percent

Returns:

  • (Object)

    the current value of ip7percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip7percent
  @ip7percent
end

#ip7pulsesObject

Returns the value of attribute ip7pulses

Returns:

  • (Object)

    the current value of ip7pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip7pulses
  @ip7pulses
end

#ip8percentObject

Returns the value of attribute ip8percent

Returns:

  • (Object)

    the current value of ip8percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip8percent
  @ip8percent
end

#ip8pulsesObject

Returns the value of attribute ip8pulses

Returns:

  • (Object)

    the current value of ip8pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip8pulses
  @ip8pulses
end

#ip9percentObject

Returns the value of attribute ip9percent

Returns:

  • (Object)

    the current value of ip9percent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip9percent
  @ip9percent
end

#ip9pulsesObject

Returns the value of attribute ip9pulses

Returns:

  • (Object)

    the current value of ip9pulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def ip9pulses
  @ip9pulses
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def label
  @label
end

#last_action_causeObject

Returns the value of attribute last_action_cause

Returns:

  • (Object)

    the current value of last_action_cause



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def last_action_cause
  @last_action_cause
end

#last_action_sourceObject

Returns the value of attribute last_action_source

Returns:

  • (Object)

    the current value of last_action_source



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

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



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def last_direction
  @last_direction
end

#positionpercentObject

Returns the value of attribute positionpercent

Returns:

  • (Object)

    the current value of positionpercent



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def positionpercent
  @positionpercent
end

#positionpulsesObject

Returns the value of attribute positionpulses

Returns:

  • (Object)

    the current value of positionpulses



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def positionpulses
  @positionpulses
end

#slowspeedObject

Returns the value of attribute slowspeed

Returns:

  • (Object)

    the current value of slowspeed



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def slowspeed
  @slowspeed
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def state
  @state
end

#uplimitObject

Returns the value of attribute uplimit

Returns:

  • (Object)

    the current value of uplimit



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def uplimit
  @uplimit
end

#upspeedObject

Returns the value of attribute upspeed

Returns:

  • (Object)

    the current value of upspeed



6
7
8
# File 'lib/sdn/mqtt_bridge.rb', line 6

def upspeed
  @upspeed
end

Instance Method Details

#add_group(index, address) ⇒ Object



68
69
70
71
72
# File 'lib/sdn/mqtt_bridge.rb', line 68

def add_group(index, address)
  bridge.add_group(SDN::Message.print_address(address)) if address
  @groups[index] = address
  publish(:groups, groups_string)
end

#groups_stringObject



89
90
91
# File 'lib/sdn/mqtt_bridge.rb', line 89

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

#publish(attribute, value) ⇒ Object



61
62
63
64
65
66
# File 'lib/sdn/mqtt_bridge.rb', line 61

def publish(attribute, value)
  if self[attribute] != value
    bridge.publish("#{addr}/#{attribute}", value.to_s)
    self[attribute] = value
  end
end

#set_groups(groups) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sdn/mqtt_bridge.rb', line 74

def set_groups(groups)
  return unless groups =~ /^(?:\h{2}[:.]?\h{2}[:.]?\h{2}(?:,\h{2}[:.]?\h{2}[:.]?\h{2})*)?$/i
  groups = groups.split(',').sort.uniq.map { |g| SDN::Message.parse_address(g) }
  groups.fill(nil, groups.length, 16 - groups.length)
  messages = []
  sdn_addr = SDN::Message.parse_address(addr)
  groups.each_with_index do |g, i|
    if @groups[i] != g
      messages << SDN::Message::SetGroupAddr.new(sdn_addr, i, g)
      messages << SDN::Message::GetGroupAddr.new(sdn_addr, i)
    end
  end
  messages
end