 
     case new_device_cert do
       {:ok, data} ->
+        # DO NOT DO THIS. The api will do it behind the scenes
+        # Asset.update_device!(%{update_channel: detect_update_channel()})
         FarmbotCore.Logger.debug(3, "DeviceCert created: #{inspect(data)}")
         FarmbotCore.Logger.debug(3, "Waiting for cert and key data from AMQP from farmbot api...")
         {:noreply, state}

  def handle_call({:handle_nerves_hub_update_available, %{"firmware_url" => url}}, _from, state) do
    case Asset.fbos_config(:os_auto_update) do
      true ->
        FarmbotCore.Logger.success(1, "Applying OTA update")
        {:reply, :apply, %{state | is_applying_update: true, firmware_url: url}}

      _ ->

    :ok
  end

  def detect_deployment_tags() do
    update_channel = detect_update_channel()
    ["application:#{Project.env()}", "channel:#{update_channel}"]
  end

  def detect_update_channel() do
    if String.match?(
         ~r/v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-rc(0|[1-9]\d*)+?/,
         Project.version()
       ) do
      "beta"
    else
      case Project.branch() do
        "master" -> "stable"
        branch -> branch
      end
    end
  end
end
