       BotState.set_job_progress("FBOS_OTA", prog)
     end
 
+    :ok
+  end
+
+  def set_firmware_needs_flash() do
+    Config.update_config_value(:bool, "settings", "firmware_needs_flash", true)
+    Config.update_config_value(:bool, "settings", "firmware_needs_open", false)
     :ok
   end
 

  end

  def handle_cast({:handle_nerves_hub_fwup_message, {:progress, percent}}, state) do
    Config.update_config_value(:bool, "settings", "firmware_needs_flash", true)
    Config.update_config_value(:bool, "settings", "firmware_needs_open", false)

    _ = set_ota_progress(percent)
    {:noreply, state}
  end

  def handle_cast({:handle_nerves_hub_fwup_message, {:ok, _, _info}}, state) do
    Config.update_config_value(:bool, "settings", "firmware_needs_flash", true)
    Config.update_config_value(:bool, "settings", "firmware_needs_open", false)

    _ = set_ota_progress(100)
    {:noreply, state}
  end


      data ->
        FarmbotCore.Logger.busy(1, "Applying OTA update")
        _ = set_firmware_needs_flash()

        spawn_link(fn -> NervesHub.update() end)
        {:reply, data, %{state | is_applying_update: true}}
