Skip to content

Commit

Permalink
Don't include batt in location message if extended data is not set
Browse files Browse the repository at this point in the history
Fixes #741
  • Loading branch information
growse committed Aug 3, 2023
1 parent 7d000a0 commit 1d622f2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Both cloud and local backup should work now
- Config export actually exports to a local file now, rather than just a somewhat useless "share"
- `conn` value correctly filled out as `o` (offline) when there's no network connection (#1442)
- `batt` is ommitted from locations if extended data is disabled (#741)

## Version 2.4.10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class MessageLocation(private val dep: MessageWithCreatedAt = MessageCreate
var trigger: String? = null

@JsonProperty("batt")
var battery = 0
var battery: Int? = null

@JsonProperty("bs")
var batteryStatus: BatteryStatus? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import timber.log.Timber

@Singleton
class DeviceMetricsProvider @Inject internal constructor(@ApplicationContext private val context: Context) {
val batteryLevel: Int
val batteryLevel: Int?
get() {
val intentFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
val batteryStatus = context.registerReceiver(null, intentFilter)
return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, 0) ?: 0
return context
.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
?.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
}
val batteryStatus: BatteryStatus
get() {
Expand Down
2 changes: 1 addition & 1 deletion project/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ To allow this, please enable Location in the device settings."</string>
<string name="preferencesPortValidationError">"Port must be a number between 1 and 65535"</string>
<string name="preferencesProfileId">"Mode"</string>
<string name="preferencesPubExtendedData">"Extended data"</string>
<string name="preferencesPubExtendedDataSummary">"Include extended data in location reports"</string>
<string name="preferencesPubExtendedDataSummary">"Include battery status, connection type and monitoring mode in location reports"</string>
<string name="preferencesRemoteCommand">"Remote commands"</string>
<string name="preferencesRemoteCommandSummary">"Enable remote commands"</string>
<string name="preferencesRemoteConfiguration">"Remote configuration"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class ParserTest {
"_type" : "location",
"acc" : 10,
"alt" : 20,
"batt" : 0,
"created_at" : 25,
"inregions" : [ "Testregion1", "Testregion2" ],
"lat" : 50.1,
Expand Down Expand Up @@ -157,7 +156,7 @@ class ParserTest {
assertEquals("s5", message.trackerId)
assertEquals(1600, message.accuracy.toLong())
assertEquals(0.0, message.altitude.toDouble(), 0.0)
assertEquals(99, message.battery.toLong())
assertEquals(99, message.battery)
assertEquals(BatteryStatus.FULL, message.batteryStatus)
assertEquals("w", message.conn)
assertEquals(52.3153748, message.latitude, 0.0)
Expand Down Expand Up @@ -422,7 +421,7 @@ class ParserTest {
assertEquals("s5", messageLocation.trackerId)
assertEquals(1600, messageLocation.accuracy.toLong())
assertEquals(0.0, messageLocation.altitude.toDouble(), 0.0)
assertEquals(99, messageLocation.battery.toLong())
assertEquals(99, messageLocation.battery)
assertEquals("w", messageLocation.conn)
assertEquals(52.3153748, messageLocation.latitude, 0.0)
assertEquals(5.0408462, messageLocation.longitude, 0.0)
Expand Down

0 comments on commit 1d622f2

Please sign in to comment.