Skip to content

Commit

Permalink
Add package name to health connect sensors, additional sensor tweaks (#…
Browse files Browse the repository at this point in the history
…4750)

* Add package name to health connect sensors, additional sensor tweaks

* Update attribute name
  • Loading branch information
dshokouhi authored Oct 23, 2024
1 parent ba75715 commit 751e250
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class HealthConnectSensorManager : SensorManager {
"mdi:fire",
"energy",
unitOfMeasurement = "kcal",
stateClass = SensorManager.STATE_CLASS_TOTAL_INCREASING,
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC
)

Expand All @@ -60,7 +61,7 @@ class HealthConnectSensorManager : SensorManager {
type = "sensor",
commonR.string.basic_sensor_name_weight,
commonR.string.sensor_description_weight,
"mdi:weight",
"mdi:scale-bathroom",
unitOfMeasurement = "g",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
deviceClass = "weight"
Expand Down Expand Up @@ -104,13 +105,16 @@ class HealthConnectSensorManager : SensorManager {
)
)
}
totalCaloriesBurnedRequest[TotalCaloriesBurnedRecord.ENERGY_TOTAL]?.let {
totalCaloriesBurnedRequest[TotalCaloriesBurnedRecord.ENERGY_TOTAL]?.let { energy ->
onSensorUpdated(
context,
totalCaloriesBurned,
BigDecimal(it.inKilocalories).setScale(2, RoundingMode.HALF_EVEN),
BigDecimal(energy.inKilocalories).setScale(2, RoundingMode.HALF_EVEN),
totalCaloriesBurned.statelessIcon,
attributes = mapOf("endTime" to LocalDateTime.of(LocalDate.now(), LocalTime.now()).toInstant(ZoneOffset.UTC))
attributes = mapOf(
"endTime" to LocalDateTime.of(LocalDate.now(), LocalTime.now()).toInstant(ZoneOffset.UTC),
"sources" to totalCaloriesBurnedRequest.dataOrigins.map { it.packageName }
)
)
}
}
Expand All @@ -135,7 +139,10 @@ class HealthConnectSensorManager : SensorManager {
weight,
BigDecimal(response.records.last().weight.inGrams).setScale(2, RoundingMode.HALF_EVEN),
weight.statelessIcon,
attributes = mapOf("date" to response.records.last().time)
attributes = mapOf(
"date" to response.records.last().time,
"source" to response.records.last().metadata.dataOrigin.packageName
)
)
}

Expand All @@ -160,7 +167,10 @@ class HealthConnectSensorManager : SensorManager {
activeCaloriesBurned,
BigDecimal(response.records.last().energy.inKilocalories).setScale(2, RoundingMode.HALF_EVEN),
activeCaloriesBurned.statelessIcon,
attributes = mapOf("endTime" to response.records.last().endTime)
attributes = mapOf(
"endTime" to response.records.last().endTime,
"source" to response.records.last().metadata.dataOrigin.packageName
)
)
}

Expand Down

0 comments on commit 751e250

Please sign in to comment.