Skip to content

Commit

Permalink
Full variant
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Apr 22, 2022
1 parent 3b4ad87 commit 59fa9d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.google.android.gms.location.LocationServices
import io.homeassistant.companion.android.common.sensors.SensorManager
import io.homeassistant.companion.android.database.AppDatabase
import io.homeassistant.companion.android.database.sensor.SensorSetting
import io.homeassistant.companion.android.database.sensor.SensorSettingType
import io.homeassistant.companion.android.location.HighAccuracyLocationService
import io.homeassistant.companion.android.common.R as commonR

Expand Down Expand Up @@ -73,7 +74,7 @@ class GeocodeSensorManager : SensorManager {
val minAccuracy = sensorSettings
.firstOrNull { it.name == SETTING_ACCURACY }?.value?.toIntOrNull()
?: DEFAULT_MINIMUM_ACCURACY
sensorDao.add(SensorSetting(geocodedLocation.id, SETTING_ACCURACY, minAccuracy.toString(), "number"))
sensorDao.add(SensorSetting(geocodedLocation.id, SETTING_ACCURACY, minAccuracy.toString(), SensorSettingType.NUMBER))

if (location.accuracy <= minAccuracy)
address = Geocoder(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.homeassistant.companion.android.common.util.DisabledLocationHandler
import io.homeassistant.companion.android.database.AppDatabase
import io.homeassistant.companion.android.database.sensor.Attribute
import io.homeassistant.companion.android.database.sensor.SensorSetting
import io.homeassistant.companion.android.database.sensor.SensorSettingType
import io.homeassistant.companion.android.location.HighAccuracyLocationService
import io.homeassistant.companion.android.notifications.MessagingManager
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -127,7 +128,7 @@ class LocationSensorManager : LocationSensorManagerBase() {

fun setHighAccuracyModeSetting(context: Context, enabled: Boolean) {
val sensorDao = AppDatabase.getInstance(context).sensorDao()
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE, enabled.toString(), "toggle"))
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE, enabled.toString(), SensorSettingType.TOGGLE))
}

fun getHighAccuracyModeIntervalSetting(context: Context): Int {
Expand All @@ -138,7 +139,7 @@ class LocationSensorManager : LocationSensorManagerBase() {

fun setHighAccuracyModeIntervalSetting(context: Context, updateInterval: Int) {
val sensorDao = AppDatabase.getInstance(context).sensorDao()
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE_UPDATE_INTERVAL, updateInterval.toString(), "number"))
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE_UPDATE_INTERVAL, updateInterval.toString(), SensorSettingType.NUMBER))
}
}

Expand Down Expand Up @@ -310,7 +311,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
latestContext,
LocationSensorManager.backgroundLocation,
SETTING_HIGH_ACCURACY_MODE_UPDATE_INTERVAL,
"number",
SensorSettingType.NUMBER,
DEFAULT_UPDATE_INTERVAL_HA_SECONDS.toString()
)

Expand Down Expand Up @@ -351,7 +352,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
latestContext,
LocationSensorManager.backgroundLocation,
SETTING_HIGH_ACCURACY_MODE_BLUETOOTH_DEVICES,
"list-bluetooth",
SensorSettingType.LIST_BLUETOOTH,
""
)

Expand Down Expand Up @@ -415,7 +416,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
latestContext,
backgroundLocation,
SETTING_HIGH_ACCURACY_MODE,
"toggle",
SensorSettingType.TOGGLE,
"false"
).toBoolean()
}
Expand Down Expand Up @@ -495,7 +496,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
val minAccuracy = sensorSettings
.firstOrNull { it.name == SETTING_ACCURACY }?.value?.toIntOrNull()
?: DEFAULT_MINIMUM_ACCURACY
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_ACCURACY, minAccuracy.toString(), "number"))
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_ACCURACY, minAccuracy.toString(), SensorSettingType.NUMBER))
if (location.accuracy > minAccuracy) {
Log.w(TAG, "Location accuracy didn't meet requirements, disregarding: $location")
} else {
Expand Down Expand Up @@ -594,7 +595,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
val minAccuracy = sensorSettings
.firstOrNull { it.name == SETTING_ACCURACY }?.value?.toIntOrNull()
?: DEFAULT_MINIMUM_ACCURACY
sensorDao.add(SensorSetting(zoneLocation.id, SETTING_ACCURACY, minAccuracy.toString(), "number"))
sensorDao.add(SensorSetting(zoneLocation.id, SETTING_ACCURACY, minAccuracy.toString(), SensorSettingType.NUMBER))

if (geofencingEvent.triggeringLocation.accuracy > minAccuracy) {
Log.w(
Expand Down Expand Up @@ -757,7 +758,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
latestContext,
backgroundLocation,
SETTING_HIGH_ACCURACY_MODE_TRIGGER_RANGE_ZONE,
"number",
SensorSettingType.NUMBER,
DEFAULT_TRIGGER_RANGE_METERS.toString()
)

Expand All @@ -766,7 +767,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
highAccuracyTriggerRangeInt = DEFAULT_TRIGGER_RANGE_METERS

val sensorDao = AppDatabase.getInstance(latestContext).sensorDao()
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE_TRIGGER_RANGE_ZONE, highAccuracyTriggerRangeInt.toString(), "number"))
sensorDao.add(SensorSetting(backgroundLocation.id, SETTING_HIGH_ACCURACY_MODE_TRIGGER_RANGE_ZONE, highAccuracyTriggerRangeInt.toString(), SensorSettingType.NUMBER))
}

return highAccuracyTriggerRangeInt
Expand All @@ -781,7 +782,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
latestContext,
backgroundLocation,
SETTING_HIGH_ACCURACY_MODE_ZONE,
"list-zones",
SensorSettingType.LIST_ZONES,
""
)

Expand Down Expand Up @@ -812,18 +813,18 @@ class LocationSensorManager : LocationSensorManagerBase() {
val minAccuracy = sensorSettings
.firstOrNull { it.name == SETTING_ACCURACY }?.value?.toIntOrNull()
?: DEFAULT_MINIMUM_ACCURACY
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_ACCURACY, minAccuracy.toString(), "number"))
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_ACCURACY, minAccuracy.toString(), SensorSettingType.NUMBER))
val minTimeBetweenUpdates = sensorSettings
.firstOrNull { it.name == SETTING_ACCURATE_UPDATE_TIME }?.value?.toIntOrNull()
?: 60000
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_ACCURATE_UPDATE_TIME, minTimeBetweenUpdates.toString(), "number"))
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_ACCURATE_UPDATE_TIME, minTimeBetweenUpdates.toString(), SensorSettingType.NUMBER))

// Only update accurate location at most once a minute
if (now < latestAccurateLocation + minTimeBetweenUpdates) {
Log.d(TAG, "Not requesting accurate location, last accurate location was too recent")
return
}
sensorDao.add(Attribute(singleAccurateLocation.id, "lastAccurateLocationRequest", now.toString(), "string"))
sensorDao.add(Attribute(singleAccurateLocation.id, "lastAccurateLocationRequest", now.toString(), SensorSettingType.STRING))

val maxRetries = 5
val request = createLocationRequest().apply {
Expand Down Expand Up @@ -938,6 +939,6 @@ class LocationSensorManager : LocationSensorManagerBase() {
)
}
} else
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_INCLUDE_SENSOR_UPDATE, "false", "toggle"))
sensorDao.add(SensorSetting(singleAccurateLocation.id, SETTING_INCLUDE_SENSOR_UPDATE, "false", SensorSettingType.TOGGLE))
}
}

0 comments on commit 59fa9d6

Please sign in to comment.