Class: SDN::CLI::MQTT::Motor
- Inherits:
-
Struct
- Object
- Struct
- SDN::CLI::MQTT::Motor
- Defined in:
- lib/sdn/cli/mqtt/motor.rb
Instance Attribute Summary collapse
-
#addr ⇒ Object
Returns the value of attribute addr.
-
#bridge ⇒ Object
Returns the value of attribute bridge.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#down_limit ⇒ Object
Returns the value of attribute down_limit.
-
#down_speed ⇒ Object
Returns the value of attribute down_speed.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#ip10_percent ⇒ Object
Returns the value of attribute ip10_percent.
-
#ip10_pulses ⇒ Object
Returns the value of attribute ip10_pulses.
-
#ip11_percent ⇒ Object
Returns the value of attribute ip11_percent.
-
#ip11_pulses ⇒ Object
Returns the value of attribute ip11_pulses.
-
#ip12_percent ⇒ Object
Returns the value of attribute ip12_percent.
-
#ip12_pulses ⇒ Object
Returns the value of attribute ip12_pulses.
-
#ip13_percent ⇒ Object
Returns the value of attribute ip13_percent.
-
#ip13_pulses ⇒ Object
Returns the value of attribute ip13_pulses.
-
#ip14_percent ⇒ Object
Returns the value of attribute ip14_percent.
-
#ip14_pulses ⇒ Object
Returns the value of attribute ip14_pulses.
-
#ip15_percent ⇒ Object
Returns the value of attribute ip15_percent.
-
#ip15_pulses ⇒ Object
Returns the value of attribute ip15_pulses.
-
#ip16_percent ⇒ Object
Returns the value of attribute ip16_percent.
-
#ip16_pulses ⇒ Object
Returns the value of attribute ip16_pulses.
-
#ip1_percent ⇒ Object
Returns the value of attribute ip1_percent.
-
#ip1_pulses ⇒ Object
Returns the value of attribute ip1_pulses.
-
#ip2_percent ⇒ Object
Returns the value of attribute ip2_percent.
-
#ip2_pulses ⇒ Object
Returns the value of attribute ip2_pulses.
-
#ip3_percent ⇒ Object
Returns the value of attribute ip3_percent.
-
#ip3_pulses ⇒ Object
Returns the value of attribute ip3_pulses.
-
#ip4_percent ⇒ Object
Returns the value of attribute ip4_percent.
-
#ip4_pulses ⇒ Object
Returns the value of attribute ip4_pulses.
-
#ip5_percent ⇒ Object
Returns the value of attribute ip5_percent.
-
#ip5_pulses ⇒ Object
Returns the value of attribute ip5_pulses.
-
#ip6_percent ⇒ Object
Returns the value of attribute ip6_percent.
-
#ip6_pulses ⇒ Object
Returns the value of attribute ip6_pulses.
-
#ip7_percent ⇒ Object
Returns the value of attribute ip7_percent.
-
#ip7_pulses ⇒ Object
Returns the value of attribute ip7_pulses.
-
#ip8_percent ⇒ Object
Returns the value of attribute ip8_percent.
-
#ip8_pulses ⇒ Object
Returns the value of attribute ip8_pulses.
-
#ip9_percent ⇒ Object
Returns the value of attribute ip9_percent.
-
#ip9_pulses ⇒ Object
Returns the value of attribute ip9_pulses.
-
#label ⇒ Object
Returns the value of attribute label.
-
#last_action ⇒ Object
Returns the value of attribute last_action.
-
#last_action_cause ⇒ Object
Returns the value of attribute last_action_cause.
-
#last_action_source ⇒ Object
Returns the value of attribute last_action_source.
-
#last_direction ⇒ Object
Returns the value of attribute last_direction.
-
#last_position_pulses ⇒ Object
Returns the value of attribute last_position_pulses.
-
#node_type ⇒ Object
Returns the value of attribute node_type.
-
#position_percent ⇒ Object
Returns the value of attribute position_percent.
-
#position_pulses ⇒ Object
Returns the value of attribute position_pulses.
-
#slow_speed ⇒ Object
Returns the value of attribute slow_speed.
-
#state ⇒ Object
Returns the value of attribute state.
-
#up_limit ⇒ Object
Returns the value of attribute up_limit.
-
#up_speed ⇒ Object
Returns the value of attribute up_speed.
Instance Method Summary collapse
- #add_group(index, address) ⇒ Object
- #group_objects ⇒ Object
- #groups_string ⇒ Object
-
#initialize ⇒ Motor
constructor
A new instance of Motor.
- #publish(attribute, value) ⇒ Object
-
#set_groups(groups) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
Constructor Details
#initialize ⇒ Motor
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
#addr ⇒ Object
Returns the value of attribute addr
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def addr @addr end |
#bridge ⇒ Object
Returns the value of attribute bridge
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def bridge @bridge end |
#direction ⇒ Object
Returns the value of attribute direction
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def direction @direction end |
#down_limit ⇒ Object
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_speed ⇒ Object
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 |
#groups ⇒ Object
Returns the value of attribute groups
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def groups @groups end |
#ip ⇒ Object
Returns the value of attribute ip
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def ip @ip end |
#ip10_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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 |
#label ⇒ Object
Returns the value of attribute label
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def label @label end |
#last_action ⇒ Object
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_cause ⇒ Object
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_source ⇒ Object
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_direction ⇒ Object
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_pulses ⇒ Object
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_type ⇒ Object
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_percent ⇒ Object
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_pulses ⇒ Object
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_speed ⇒ Object
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 |
#state ⇒ Object
Returns the value of attribute state
6 7 8 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 6 def state @state end |
#up_limit ⇒ Object
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_speed ⇒ Object
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_objects ⇒ Object
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_string ⇒ Object
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) = [] sdn_addr = Message.parse_address(addr) groups.each_with_index do |g, i| if @groups[i] != g << Message::SetGroupAddr.new(sdn_addr, i + 1, g).tap { |m| m.ack_requested = true } << Message::GetGroupAddr.new(sdn_addr, i + 1) end end end |