class ModbusController < ApplicationController def index @schedule = Schedule.all @modbus_running = Modbus::PollingService.running? end def destroy schedule = Schedule.find_by(id: params[:id]) if schedule.destroy redirect_to schedule_edit_modbus_index_path, notice: "스케줄이 삭제되었습니다." else redirect_to schedule_edit_modbus_index_path, alert: "스케줄 삭제에 실패했습니다." end end def start Modbus::PollingService.start redirect_to modbus_index_path end def stop Modbus::PollingService.stop redirect_to modbus_index_path end def schedule_edit @schedule = Schedule.all end def schedule_edit_update error_time = [] params[:schedule].each do |id, attributes| schedule = Schedule.find_by(id: id) unless schedule.update( hour: attributes[:hour], minute: attributes[:minute], is_active: attributes[:is_active], temperature: attributes[:temperature] ) error_time << "#{schedule.hour}시 #{schedule.minute}분" end end if error_time.any? redirect_to modbus_index_path, alert: "#{error_time.join(', ')}의 온도 업데이트에 실패하였습니다." else redirect_to modbus_index_path, notice: "스케줄이 성공적으로 업데이트되었습니다." end end end