samples: sensor: Fix logically dead code in bmg160 sample

Converts the bmg160 sample application to check the sensor device at
build time instead of runtime. This fixes a Coverity issue for logically
dead code introduced in commit 5832e588e3664cc0abb76847ac3a5e4d1954392d.

Fixes #35118
Coverity-CID: 235919

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
diff --git a/samples/sensor/bmg160/src/main.c b/samples/sensor/bmg160/src/main.c
index 18fbfcf..7201dab 100644
--- a/samples/sensor/bmg160/src/main.c
+++ b/samples/sensor/bmg160/src/main.c
@@ -17,6 +17,10 @@
 #define MAX_TEST_TIME	15000
 #define SLEEPTIME	300
 
+#if !DT_HAS_COMPAT_STATUS_OKAY(bosch_bmg160)
+#error "No bosch,bmg160 compatible node found in the device tree"
+#endif
+
 static void print_gyro_data(const struct device *bmg160)
 {
 	struct sensor_value val[3];
@@ -173,10 +177,6 @@
 	struct sensor_value attr;
 #endif
 
-	if (!bmg160) {
-		printf("Device not found.\n");
-		return;
-	}
 	if (!device_is_ready(bmg160)) {
 		printf("Device %s is not ready.\n", bmg160->name);
 		return;