From cabd41e6d5f64fe5218dcbf6be2d6a838f7e6885 Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Mon, 26 Sep 2022 07:55:02 -0700 Subject: [PATCH] Breaking Change: Only update geocoded sensor with location if the setting is turned on (#2913) * Add a setting to control if the geocoded sensor should update with device tracker * Update strings for settings --- .../android/sensors/GeocodeSensorManager.kt | 1 + .../android/sensors/LocationSensorManager.kt | 21 +++++++++++++++---- common/src/main/res/values/strings.xml | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/sensors/GeocodeSensorManager.kt b/app/src/full/java/io/homeassistant/companion/android/sensors/GeocodeSensorManager.kt index 6aad20ec6..0f96d490b 100644 --- a/app/src/full/java/io/homeassistant/companion/android/sensors/GeocodeSensorManager.kt +++ b/app/src/full/java/io/homeassistant/companion/android/sensors/GeocodeSensorManager.kt @@ -18,6 +18,7 @@ class GeocodeSensorManager : SensorManager { companion object { private const val SETTING_ACCURACY = "geocode_minimum_accuracy" + const val SETTINGS_INCLUDE_LOCATION = "geocode_include_location_updates" private const val DEFAULT_MINIMUM_ACCURACY = 200 private const val TAG = "GeocodeSM" val geocodedLocation = SensorManager.BasicSensor( diff --git a/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt b/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt index a36ad35fb..4dd43569c 100644 --- a/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt +++ b/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt @@ -766,16 +766,29 @@ class LocationSensorManager : LocationSensorManagerBase() { lastLocationSend = now lastUpdateLocation = updateLocation.gps.contentToString() + val geocodeIncludeLocation = getSetting( + latestContext, + GeocodeSensorManager.geocodedLocation, + GeocodeSensorManager.SETTINGS_INCLUDE_LOCATION, + SensorSettingType.TOGGLE, + "false" + ).toBoolean() + ioScope.launch { try { integrationUseCase.updateLocation(updateLocation) Log.d(TAG, "Location update sent successfully") // Update Geocoded Location Sensor - val intent = Intent(latestContext, SensorReceiver::class.java) - intent.action = SensorReceiverBase.ACTION_UPDATE_SENSOR - intent.putExtra(SensorReceiverBase.EXTRA_SENSOR_ID, GeocodeSensorManager.geocodedLocation.id) - latestContext.sendBroadcast(intent) + if (geocodeIncludeLocation) { + val intent = Intent(latestContext, SensorReceiver::class.java) + intent.action = SensorReceiverBase.ACTION_UPDATE_SENSOR + intent.putExtra( + SensorReceiverBase.EXTRA_SENSOR_ID, + GeocodeSensorManager.geocodedLocation.id + ) + latestContext.sendBroadcast(intent) + } } catch (e: Exception) { Log.e(TAG, "Could not update location.", e) } diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index a99b965fa..37e377254 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -478,7 +478,7 @@ The current state of Do Not Disturb Whether the device is in Doze mode Information about the total and available storage space externally - Calculated address based on GPS data using Googles Location API + Calculated address based on GPS data using Googles Location API. The minimum accuracy setting determines if a location update is accurate enough to be updated, the default is 200 meters. A setting also exists to send a sensor update anytime the location sensors update, by default this off. Whether headphones are plugged into the device Whether the headset is currently in use Whether high accuracy mode is active on the device @@ -588,6 +588,7 @@ Filter Iterations Filter RSSI Multiplier Minimum Accuracy + Update sensor with location sensors Deadband Add New Intent Intent %1$1s