Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#162193] Add clearer secondary outlet message #4222

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/instrument_relays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def create
def handle_relay(action_string)
@relay = @product.replace_relay(relay_params, params[:relay][:control_mechanism])
if @relay.valid?
@relay.try(:activate_secondary_outlet)
flash[:notice] = "Relay was successfully updated."
redirect_to facility_instrument_relays_path(current_facility, @product)
else
Expand Down
21 changes: 7 additions & 14 deletions app/models/power_relay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,30 @@ def toggle(status)
toggled_status = relay_connection.toggle(outlet, status)
if secondary_outlet
secondary_toggled_status = relay_connection.toggle(secondary_outlet, status)
handle_mismatch_status(status, toggled_status) if toggled_status != secondary_toggled_status
end
toggled_status
end
end

# This method will toggle the secondary outlet to match the primary outlet.
# Useful to sync up the outlets whenever the secondary outlet changes.
def activate_secondary_outlet
primary_outlet_status = relay_connection.status(outlet)
relay_connection.toggle(secondary_outlet, primary_outlet_status)
end

# Returns:
# boolean - The current on/off status of the outlet (and secondary outlet, if configured).
def query_status
log_power_relay_connection(:status) do
relay_status = relay_connection.status(outlet)
if secondary_outlet
secondary_outlet_status = relay_connection.status(secondary_outlet)
handle_mismatch_status if relay_status != secondary_outlet_status
end
relay_status
end
end

# Returns:
# string - an error
def handle_mismatch_status(requested_status=nil, primary_status=nil)
event = if requested_status.present?
"toggling relays (#{requested_status ? "on" : "off"})"
else
"querying status"
end
msg = "Outlet statuses don't match after #{event} for relay #{id} - outlet #{outlet} is (#{primary_status ? "on" : "off"}), outlet #{secondary_outlet} is (#{primary_status ? "off" : "on"})"
Rollbar.error(msg, relay: id)
end

def relay_connection
raise NotImplementedError.new("Subclass must define")
end
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,9 @@ en:
instruct:
ip_port: "Leave blank unless your device is on a non-standard port"
outlet: "e.g. 1 or 2"
secondary_outlet: "turned on/off in sync with the outlet above (Synaccess only)"
secondary_outlet: |
This outlet will be turned on/off in sync with the outlet above (Synaccess only). <br>
If you enter a value in this field, you must toggle the relay to activate.
reservation:
instruct:
reserve_interval: "The minutes of an hour on which a reservation is allowed to begin (e.g. if 5 reservations can be scheduled every 5 minutes)"
Expand Down
11 changes: 6 additions & 5 deletions spec/system/admin/instrument_relay_tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:user) { FactoryBot.create(:user, :administrator) }

before do
allow_any_instance_of(RelaySynaccessRevA).to receive(:activate_secondary_outlet).and_return(true)
login_as user
visit facility_instrument_relays_path(facility, instrument)
end
Expand Down Expand Up @@ -104,7 +105,7 @@
fill_in "relay_building_room_number", with: "1a"
fill_in "relay_circuit_number", with: "1"
fill_in "relay_ethernet_port_number", with: "2000"

click_button "Save"
instrument.reload
expect(instrument.relay).to be_present
Expand Down Expand Up @@ -136,7 +137,7 @@
click_button "Save"
expect(page).to have_content("Outlet has already been taken")
end

context "both instruments have the same schedule" do
let!(:instrument2) { create(:instrument, facility: facility, no_relay: true, schedule: instrument.schedule) }
let!(:existing_relay) { create(:relay_syna, instrument: instrument2) }
Expand Down Expand Up @@ -199,7 +200,7 @@

context "switching relay types" do
let(:instrument) { FactoryBot.create(:setup_instrument, facility: facility, relay: build(:relay)) }

before do
click_link "Edit"
end
Expand All @@ -213,7 +214,7 @@

expect(instrument.relay).to be_a(RelayDummy)
end

end

context "from relay to reservation only" do
Expand All @@ -226,7 +227,7 @@

expect(instrument.relay).not_to be_present
end

end

context "from reservation only to timer" do
Expand Down