mirror of
https://github.com/home-assistant/android
synced 2024-09-06 17:23:32 +00:00
Add new force_on and force_off options to command_high_accuracy_mode. (#2924)
This commit is contained in:
parent
c2937e77aa
commit
203e6868d1
|
@ -140,6 +140,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
private var lastHighAccuracyMode = false
|
||||
private var lastHighAccuracyUpdateInterval = DEFAULT_UPDATE_INTERVAL_HA_SECONDS
|
||||
private var forceHighAccuracyModeOn = false
|
||||
private var forceHighAccuracyModeOff = false
|
||||
private var highAccuracyModeEnabled = false
|
||||
|
||||
private var lastEnteredGeoZones: MutableList<String> = ArrayList()
|
||||
|
@ -182,17 +183,27 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
ACTION_FORCE_HIGH_ACCURACY -> {
|
||||
var command = intent.extras?.get("command")?.toString()
|
||||
when (command) {
|
||||
MessagingManager.TURN_ON, MessagingManager.TURN_OFF -> {
|
||||
var turnOn = command == MessagingManager.TURN_ON
|
||||
MessagingManager.TURN_ON, MessagingManager.TURN_OFF, MessagingManager.FORCE_ON -> {
|
||||
var turnOn = command != MessagingManager.TURN_OFF
|
||||
if (turnOn) Log.d(TAG, "Forcing of high accuracy mode enabled")
|
||||
else Log.d(TAG, "Forcing of high accuracy mode disabled")
|
||||
forceHighAccuracyModeOn = turnOn
|
||||
forceHighAccuracyModeOff = false
|
||||
setHighAccuracyModeSetting(latestContext, turnOn)
|
||||
ioScope.launch {
|
||||
setupBackgroundLocation()
|
||||
}
|
||||
}
|
||||
|
||||
MessagingManager.FORCE_OFF -> {
|
||||
Log.d(TAG, "High accuracy mode forced off")
|
||||
forceHighAccuracyModeOn = false
|
||||
forceHighAccuracyModeOff = true
|
||||
ioScope.launch {
|
||||
setupBackgroundLocation()
|
||||
}
|
||||
}
|
||||
|
||||
MessagingManager.HIGH_ACCURACY_SET_UPDATE_INTERVAL -> {
|
||||
if (lastHighAccuracyMode)
|
||||
restartHighAccuracyService(getHighAccuracyModeIntervalSetting(latestContext))
|
||||
|
@ -388,17 +399,26 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
|
||||
val shouldEnableHighAccuracyMode = shouldEnableHighAccuracyMode()
|
||||
|
||||
// As soon as the high accuracy mode should be enabled, disable the force of high accuracy mode!
|
||||
if (shouldEnableHighAccuracyMode) {
|
||||
// As soon as the high accuracy mode should be enabled, disable the force_on of high accuracy mode!
|
||||
if (shouldEnableHighAccuracyMode && forceHighAccuracyModeOn) {
|
||||
Log.d(TAG, "Forcing of high accuracy mode disabled, because high accuracy mode had to be enabled anyway.")
|
||||
forceHighAccuracyModeOn = false
|
||||
}
|
||||
|
||||
return if (!forceHighAccuracyModeOn) {
|
||||
shouldEnableHighAccuracyMode
|
||||
} else {
|
||||
// As soon as the high accuracy mode shouldn't be enabled, disable the force_off of high accuracy mode!
|
||||
if (!shouldEnableHighAccuracyMode && forceHighAccuracyModeOff) {
|
||||
Log.d(TAG, "Forcing off of high accuracy mode disabled, because high accuracy mode had to be disabled anyway.")
|
||||
forceHighAccuracyModeOff = false
|
||||
}
|
||||
|
||||
return if (forceHighAccuracyModeOn) {
|
||||
Log.d(TAG, "High accuracy mode enabled, because command_high_accuracy_mode was used to turn it on")
|
||||
true
|
||||
} else if (forceHighAccuracyModeOff) {
|
||||
Log.d(TAG, "High accuracy mode disabled, because command_high_accuracy_mode was used to force it off")
|
||||
false
|
||||
} else {
|
||||
shouldEnableHighAccuracyMode
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -461,7 +481,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
|
||||
btDevConnected = bluetoothDevices.any { it.connected && highAccuracyModeBTDevices.contains(it.address) }
|
||||
|
||||
if (!forceHighAccuracyModeOn) {
|
||||
if (!forceHighAccuracyModeOn && !forceHighAccuracyModeOff) {
|
||||
if (!btDevConnected) Log.d(TAG, "High accuracy mode disabled, because defined ($highAccuracyModeBTDevices) bluetooth device(s) not connected (Connected devices: $bluetoothDevices)")
|
||||
else Log.d(TAG, "High accuracy mode enabled, because defined ($highAccuracyModeBTDevices) bluetooth device(s) connected (Connected devices: $bluetoothDevices)")
|
||||
}
|
||||
|
@ -479,7 +499,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
|
||||
inZone = zoneExpEntered || zoneExited
|
||||
|
||||
if (!forceHighAccuracyModeOn) {
|
||||
if (!forceHighAccuracyModeOn && !forceHighAccuracyModeOff) {
|
||||
if (!inZone) Log.d(TAG, "High accuracy mode disabled, because not in zone $highAccuracyExpZones")
|
||||
else Log.d(TAG, "High accuracy mode enabled, because in zone $highAccuracyExpZones")
|
||||
}
|
||||
|
|
|
@ -227,6 +227,8 @@ class MessagingManager @Inject constructor(
|
|||
|
||||
// High accuracy commands
|
||||
const val HIGH_ACCURACY_SET_UPDATE_INTERVAL = "high_accuracy_set_update_interval"
|
||||
const val FORCE_ON = "force_on"
|
||||
const val FORCE_OFF = "force_off"
|
||||
|
||||
// Command groups
|
||||
val DEVICE_COMMANDS = listOf(
|
||||
|
@ -256,6 +258,7 @@ class MessagingManager @Inject constructor(
|
|||
SYSTEM_STREAM, DTMF_STREAM
|
||||
)
|
||||
val ENABLE_COMMANDS = listOf(TURN_OFF, TURN_ON)
|
||||
val FORCE_COMMANDS = listOf(FORCE_OFF, FORCE_ON)
|
||||
val MEDIA_COMMANDS = listOf(
|
||||
MEDIA_FAST_FORWARD, MEDIA_NEXT, MEDIA_PAUSE, MEDIA_PLAY,
|
||||
MEDIA_PLAY_PAUSE, MEDIA_PREVIOUS, MEDIA_REWIND, MEDIA_STOP
|
||||
|
@ -435,6 +438,7 @@ class MessagingManager @Inject constructor(
|
|||
}
|
||||
COMMAND_HIGH_ACCURACY_MODE -> {
|
||||
if ((!jsonData[COMMAND].isNullOrEmpty() && jsonData[COMMAND] in ENABLE_COMMANDS) ||
|
||||
(!jsonData[COMMAND].isNullOrEmpty() && jsonData[COMMAND] in FORCE_COMMANDS) ||
|
||||
(
|
||||
!jsonData[COMMAND].isNullOrEmpty() && jsonData[COMMAND] == HIGH_ACCURACY_SET_UPDATE_INTERVAL &&
|
||||
jsonData[HIGH_ACCURACY_UPDATE_INTERVAL]?.toIntOrNull() != null && jsonData[HIGH_ACCURACY_UPDATE_INTERVAL]?.toInt()!! >= 5
|
||||
|
@ -835,6 +839,7 @@ class MessagingManager @Inject constructor(
|
|||
when (command) {
|
||||
TURN_OFF -> LocationSensorManager.setHighAccuracyModeSetting(context, false)
|
||||
TURN_ON -> LocationSensorManager.setHighAccuracyModeSetting(context, true)
|
||||
FORCE_ON -> LocationSensorManager.setHighAccuracyModeSetting(context, true)
|
||||
HIGH_ACCURACY_SET_UPDATE_INTERVAL -> LocationSensorManager.setHighAccuracyModeIntervalSetting(context, data[HIGH_ACCURACY_UPDATE_INTERVAL]!!.toInt())
|
||||
}
|
||||
val intent = Intent(context, LocationSensorManager::class.java)
|
||||
|
|
Loading…
Reference in a new issue