Skip to content

Commit

Permalink
Store health services updates and send them with worker updates (home…
Browse files Browse the repository at this point in the history
…-assistant#3076)

* Store health services updates and send them with worker updates

* Switch update type to worker
  • Loading branch information
dshokouhi authored Nov 17, 2022
1 parent 0bccff6 commit a390865
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HealthServicesSensorManager : SensorManager {
"mdi:stairs",
unitOfMeasurement = "floors",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.WORKER
)
private val dailyDistance = SensorManager.BasicSensor(
"daily_distance",
Expand All @@ -58,7 +58,7 @@ class HealthServicesSensorManager : SensorManager {
"mdi:map-marker-distance",
unitOfMeasurement = "m",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.WORKER
)
private val dailyCalories = SensorManager.BasicSensor(
"daily_calories",
Expand All @@ -68,7 +68,7 @@ class HealthServicesSensorManager : SensorManager {
"mdi:fire",
unitOfMeasurement = "kcal",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.WORKER
)
private val dailySteps = SensorManager.BasicSensor(
"daily_steps",
Expand All @@ -78,7 +78,7 @@ class HealthServicesSensorManager : SensorManager {
"mdi:shoe-print",
unitOfMeasurement = "steps",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.WORKER
)
}

Expand Down Expand Up @@ -225,13 +225,10 @@ class HealthServicesSensorManager : SensorManager {
}
}

val hasFloorData = processDataPoint(floorsDaily, dailyFloors)
val hasDistanceData = processDataPoint(distanceDaily, dailyDistance)
val hasCalorieData = processDataPoint(caloriesDaily, dailyCalories)
val hasStepData = processDataPoint(stepsDaily, dailySteps)

if (hasFloorData || hasDistanceData || hasCalorieData || hasStepData)
SensorWorker.start(latestContext)
processDataPoint(floorsDaily, dailyFloors)
processDataPoint(distanceDaily, dailyDistance)
processDataPoint(caloriesDaily, dailyCalories)
processDataPoint(stepsDaily, dailySteps)
}

override fun onPermissionLost() {
Expand Down Expand Up @@ -319,8 +316,7 @@ class HealthServicesSensorManager : SensorManager {
private fun processDataPoint(
dataPoints: List<IntervalDataPoint<*>>,
basicSensor: SensorManager.BasicSensor
): Boolean {
var sendUpdate = false
) {
var latest = 0
var lastIndex = 0
val bootInstant =
Expand All @@ -333,7 +329,6 @@ class HealthServicesSensorManager : SensorManager {
if (endTime.toEpochMilli() > latest) {
latest = endTime.toEpochMilli().toInt()
lastIndex = index
sendUpdate = true
}
}
onSensorUpdated(
Expand All @@ -344,6 +339,5 @@ class HealthServicesSensorManager : SensorManager {
mapOf()
)
}
return sendUpdate
}
}

0 comments on commit a390865

Please sign in to comment.