Skip to content

Commit

Permalink
[#162193] Add clearer secondary outlet message (#4222)
Browse files Browse the repository at this point in the history
# Release Notes

- Improve hint message
- Remove noisy rollbar logging
- I went ahead and added logic to automatically sync up the outlets as well since it seemed pretty straightforward

# Screenshot

![Screenshot 2024-05-02 at 9 53 41 PM](https://github.com/tablexi/nucore-open/assets/30355046/39efd640-f53a-4945-972e-5119192e4667)


# Additional Context

Optional. Feel free to add/modify additional headers as appropriate, e.g. "Refactorings", "Concerns".

# Accessibility
- [ ] Did you scan for accessibility issues?
- [ ] Did you check our accessibility goal checklist?
- [ ] Did you add accessibility [specs](https://github.com/dequelabs/axe-core-gems/blob/develop/packages/axe-core-rspec/README.md)?
  • Loading branch information
giladshanan committed May 7, 2024
1 parent cf71620 commit fd027c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/controllers/instrument_relays_controller.rb
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
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
Expand Up @@ -1189,7 +1189,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
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

0 comments on commit fd027c5

Please sign in to comment.