Class: SDN::CLI::MQTT::Motor
- Inherits:
-
Struct
- Object
- Struct
- SDN::CLI::MQTT::Motor
- 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
-
#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.
- #group_objects ⇒ <SDN::CLI::MQTT::Group> readonly
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#groups_string ⇒ String
readonly
Returns the current group membership list as a normalized string.
-
#hass_state ⇒ Object
Returns the value of attribute hass_state.
-
#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_retries ⇒ Object
Returns the value of attribute last_action_retries.
-
#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) ⇒ void
Updates a group slot and refreshes derived group membership state.
-
#initialize ⇒ Motor
constructor
A new instance of Motor.
-
#set_groups(groups) ⇒ <SDN::Message>
Builds the SDN writes needed to reconcile group membership with a comma-separated list.
Constructor Details
Instance Attribute Details
#addr ⇒ Object
Returns the value of attribute addr
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def addr @addr end |
#bridge ⇒ Object
Returns the value of attribute bridge
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def bridge @bridge end |
#direction ⇒ Object
Returns the value of attribute direction
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def direction @direction end |
#down_limit ⇒ Object
Returns the value of attribute down_limit
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def down_limit @down_limit end |
#down_speed ⇒ Object
Returns the value of attribute 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)
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 |
#groups ⇒ Object
Returns the value of attribute groups
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def groups @groups end |
#groups_string ⇒ String (readonly)
Returns the current group membership list as a normalized 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_state ⇒ Object
Returns the value of attribute hass_state
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def hass_state @hass_state end |
#ip ⇒ Object
Returns the value of attribute ip
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip @ip end |
#ip10_percent ⇒ Object
Returns the value of attribute ip10_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip10_percent @ip10_percent end |
#ip10_pulses ⇒ Object
Returns the value of attribute ip10_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip10_pulses @ip10_pulses end |
#ip11_percent ⇒ Object
Returns the value of attribute ip11_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip11_percent @ip11_percent end |
#ip11_pulses ⇒ Object
Returns the value of attribute ip11_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip11_pulses @ip11_pulses end |
#ip12_percent ⇒ Object
Returns the value of attribute ip12_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip12_percent @ip12_percent end |
#ip12_pulses ⇒ Object
Returns the value of attribute ip12_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip12_pulses @ip12_pulses end |
#ip13_percent ⇒ Object
Returns the value of attribute ip13_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip13_percent @ip13_percent end |
#ip13_pulses ⇒ Object
Returns the value of attribute ip13_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip13_pulses @ip13_pulses end |
#ip14_percent ⇒ Object
Returns the value of attribute ip14_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip14_percent @ip14_percent end |
#ip14_pulses ⇒ Object
Returns the value of attribute ip14_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip14_pulses @ip14_pulses end |
#ip15_percent ⇒ Object
Returns the value of attribute ip15_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip15_percent @ip15_percent end |
#ip15_pulses ⇒ Object
Returns the value of attribute ip15_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip15_pulses @ip15_pulses end |
#ip16_percent ⇒ Object
Returns the value of attribute ip16_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip16_percent @ip16_percent end |
#ip16_pulses ⇒ Object
Returns the value of attribute ip16_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip16_pulses @ip16_pulses end |
#ip1_percent ⇒ Object
Returns the value of attribute ip1_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip1_percent @ip1_percent end |
#ip1_pulses ⇒ Object
Returns the value of attribute ip1_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip1_pulses @ip1_pulses end |
#ip2_percent ⇒ Object
Returns the value of attribute ip2_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip2_percent @ip2_percent end |
#ip2_pulses ⇒ Object
Returns the value of attribute ip2_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip2_pulses @ip2_pulses end |
#ip3_percent ⇒ Object
Returns the value of attribute ip3_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip3_percent @ip3_percent end |
#ip3_pulses ⇒ Object
Returns the value of attribute ip3_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip3_pulses @ip3_pulses end |
#ip4_percent ⇒ Object
Returns the value of attribute ip4_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip4_percent @ip4_percent end |
#ip4_pulses ⇒ Object
Returns the value of attribute ip4_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip4_pulses @ip4_pulses end |
#ip5_percent ⇒ Object
Returns the value of attribute ip5_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip5_percent @ip5_percent end |
#ip5_pulses ⇒ Object
Returns the value of attribute ip5_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip5_pulses @ip5_pulses end |
#ip6_percent ⇒ Object
Returns the value of attribute ip6_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip6_percent @ip6_percent end |
#ip6_pulses ⇒ Object
Returns the value of attribute ip6_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip6_pulses @ip6_pulses end |
#ip7_percent ⇒ Object
Returns the value of attribute ip7_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip7_percent @ip7_percent end |
#ip7_pulses ⇒ Object
Returns the value of attribute ip7_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip7_pulses @ip7_pulses end |
#ip8_percent ⇒ Object
Returns the value of attribute ip8_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip8_percent @ip8_percent end |
#ip8_pulses ⇒ Object
Returns the value of attribute ip8_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip8_pulses @ip8_pulses end |
#ip9_percent ⇒ Object
Returns the value of attribute ip9_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip9_percent @ip9_percent end |
#ip9_pulses ⇒ Object
Returns the value of attribute ip9_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def ip9_pulses @ip9_pulses end |
#label ⇒ Object
Returns the value of attribute label
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def label @label end |
#last_action ⇒ Object
Returns the value of attribute last_action
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def last_action @last_action end |
#last_action_cause ⇒ Object
Returns the value of attribute 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_retries ⇒ Object
Returns the value of attribute 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_source ⇒ Object
Returns the value of attribute last_action_source
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def last_action_source @last_action_source end |
#last_direction ⇒ Object
Returns the value of attribute last_direction
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def last_direction @last_direction end |
#last_position_pulses ⇒ Object
Returns the value of attribute last_position_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def last_position_pulses @last_position_pulses end |
#node_type ⇒ Object
Returns the value of attribute node_type
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def node_type @node_type end |
#position_percent ⇒ Object
Returns the value of attribute position_percent
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def position_percent @position_percent end |
#position_pulses ⇒ Object
Returns the value of attribute position_pulses
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def position_pulses @position_pulses end |
#slow_speed ⇒ Object
Returns the value of attribute slow_speed
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def slow_speed @slow_speed end |
#state ⇒ Object
Returns the value of attribute state
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def state @state end |
#up_limit ⇒ Object
Returns the value of attribute up_limit
7 8 9 |
# File 'lib/sdn/cli/mqtt/motor.rb', line 7 def up_limit @up_limit end |
#up_speed ⇒ Object
Returns the value of attribute 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.
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.
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) = [] 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 |