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.



77
78
79
80
81
# File 'lib/sdn/mqtt_bridge.rb', line 77

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



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def addr
  @addr
end

#bridgeObject

Returns the value of attribute bridge

Returns:

  • (Object)

    the current value of bridge



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def bridge
  @bridge
end

#directionObject

Returns the value of attribute direction

Returns:

  • (Object)

    the current value of direction



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def direction
  @direction
end

#downlimitObject

Returns the value of attribute downlimit

Returns:

  • (Object)

    the current value of downlimit



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def downlimit
  @downlimit
end

#downspeedObject

Returns the value of attribute downspeed

Returns:

  • (Object)

    the current value of downspeed



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def downspeed
  @downspeed
end

#groupsObject

Returns the value of attribute groups

Returns:

  • (Object)

    the current value of groups



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def groups
  @groups
end

#ipObject

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip
  @ip
end

#ip10percentObject

Returns the value of attribute ip10percent

Returns:

  • (Object)

    the current value of ip10percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip10percent
  @ip10percent
end

#ip10pulsesObject

Returns the value of attribute ip10pulses

Returns:

  • (Object)

    the current value of ip10pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip10pulses
  @ip10pulses
end

#ip11percentObject

Returns the value of attribute ip11percent

Returns:

  • (Object)

    the current value of ip11percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip11percent
  @ip11percent
end

#ip11pulsesObject

Returns the value of attribute ip11pulses

Returns:

  • (Object)

    the current value of ip11pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip11pulses
  @ip11pulses
end

#ip12percentObject

Returns the value of attribute ip12percent

Returns:

  • (Object)

    the current value of ip12percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip12percent
  @ip12percent
end

#ip12pulsesObject

Returns the value of attribute ip12pulses

Returns:

  • (Object)

    the current value of ip12pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip12pulses
  @ip12pulses
end

#ip13percentObject

Returns the value of attribute ip13percent

Returns:

  • (Object)

    the current value of ip13percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip13percent
  @ip13percent
end

#ip13pulsesObject

Returns the value of attribute ip13pulses

Returns:

  • (Object)

    the current value of ip13pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip13pulses
  @ip13pulses
end

#ip14percentObject

Returns the value of attribute ip14percent

Returns:

  • (Object)

    the current value of ip14percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip14percent
  @ip14percent
end

#ip14pulsesObject

Returns the value of attribute ip14pulses

Returns:

  • (Object)

    the current value of ip14pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip14pulses
  @ip14pulses
end

#ip15percentObject

Returns the value of attribute ip15percent

Returns:

  • (Object)

    the current value of ip15percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip15percent
  @ip15percent
end

#ip15pulsesObject

Returns the value of attribute ip15pulses

Returns:

  • (Object)

    the current value of ip15pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip15pulses
  @ip15pulses
end

#ip16percentObject

Returns the value of attribute ip16percent

Returns:

  • (Object)

    the current value of ip16percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip16percent
  @ip16percent
end

#ip16pulsesObject

Returns the value of attribute ip16pulses

Returns:

  • (Object)

    the current value of ip16pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip16pulses
  @ip16pulses
end

#ip1percentObject

Returns the value of attribute ip1percent

Returns:

  • (Object)

    the current value of ip1percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip1percent
  @ip1percent
end

#ip1pulsesObject

Returns the value of attribute ip1pulses

Returns:

  • (Object)

    the current value of ip1pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip1pulses
  @ip1pulses
end

#ip2percentObject

Returns the value of attribute ip2percent

Returns:

  • (Object)

    the current value of ip2percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip2percent
  @ip2percent
end

#ip2pulsesObject

Returns the value of attribute ip2pulses

Returns:

  • (Object)

    the current value of ip2pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip2pulses
  @ip2pulses
end

#ip3percentObject

Returns the value of attribute ip3percent

Returns:

  • (Object)

    the current value of ip3percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip3percent
  @ip3percent
end

#ip3pulsesObject

Returns the value of attribute ip3pulses

Returns:

  • (Object)

    the current value of ip3pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip3pulses
  @ip3pulses
end

#ip4percentObject

Returns the value of attribute ip4percent

Returns:

  • (Object)

    the current value of ip4percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip4percent
  @ip4percent
end

#ip4pulsesObject

Returns the value of attribute ip4pulses

Returns:

  • (Object)

    the current value of ip4pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip4pulses
  @ip4pulses
end

#ip5percentObject

Returns the value of attribute ip5percent

Returns:

  • (Object)

    the current value of ip5percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip5percent
  @ip5percent
end

#ip5pulsesObject

Returns the value of attribute ip5pulses

Returns:

  • (Object)

    the current value of ip5pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip5pulses
  @ip5pulses
end

#ip6percentObject

Returns the value of attribute ip6percent

Returns:

  • (Object)

    the current value of ip6percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip6percent
  @ip6percent
end

#ip6pulsesObject

Returns the value of attribute ip6pulses

Returns:

  • (Object)

    the current value of ip6pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip6pulses
  @ip6pulses
end

#ip7percentObject

Returns the value of attribute ip7percent

Returns:

  • (Object)

    the current value of ip7percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip7percent
  @ip7percent
end

#ip7pulsesObject

Returns the value of attribute ip7pulses

Returns:

  • (Object)

    the current value of ip7pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip7pulses
  @ip7pulses
end

#ip8percentObject

Returns the value of attribute ip8percent

Returns:

  • (Object)

    the current value of ip8percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip8percent
  @ip8percent
end

#ip8pulsesObject

Returns the value of attribute ip8pulses

Returns:

  • (Object)

    the current value of ip8pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip8pulses
  @ip8pulses
end

#ip9percentObject

Returns the value of attribute ip9percent

Returns:

  • (Object)

    the current value of ip9percent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip9percent
  @ip9percent
end

#ip9pulsesObject

Returns the value of attribute ip9pulses

Returns:

  • (Object)

    the current value of ip9pulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def ip9pulses
  @ip9pulses
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def label
  @label
end

#last_action_causeObject

Returns the value of attribute last_action_cause

Returns:

  • (Object)

    the current value of last_action_cause



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

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



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

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



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def last_direction
  @last_direction
end

#positionpercentObject

Returns the value of attribute positionpercent

Returns:

  • (Object)

    the current value of positionpercent



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def positionpercent
  @positionpercent
end

#positionpulsesObject

Returns the value of attribute positionpulses

Returns:

  • (Object)

    the current value of positionpulses



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def positionpulses
  @positionpulses
end

#slowspeedObject

Returns the value of attribute slowspeed

Returns:

  • (Object)

    the current value of slowspeed



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def slowspeed
  @slowspeed
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def state
  @state
end

#uplimitObject

Returns the value of attribute uplimit

Returns:

  • (Object)

    the current value of uplimit



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def uplimit
  @uplimit
end

#upspeedObject

Returns the value of attribute upspeed

Returns:

  • (Object)

    the current value of upspeed



28
29
30
# File 'lib/sdn/mqtt_bridge.rb', line 28

def upspeed
  @upspeed
end

Instance Method Details

#add_group(index, address) ⇒ Object



90
91
92
93
94
# File 'lib/sdn/mqtt_bridge.rb', line 90

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

#group_objectsObject



115
116
117
# File 'lib/sdn/mqtt_bridge.rb', line 115

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

#groups_stringObject



111
112
113
# File 'lib/sdn/mqtt_bridge.rb', line 111

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

#publish(attribute, value) ⇒ Object



83
84
85
86
87
88
# File 'lib/sdn/mqtt_bridge.rb', line 83

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

#set_groups(groups) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sdn/mqtt_bridge.rb', line 96

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