Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reset work profile state on app restart and add "intent only" update type #4765

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class DevicePolicyManager : SensorManager {
R.string.sensor_name_work_profile,
R.string.sensor_description_work_profile,
"mdi:briefcase",
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.INTENT_ONLY
)
}

override fun docsLink(): String {
return "https://companion.home-assistant.io/docs/core/sensors#work-profile-sensor"
}

private var isManagedProfileAvailable: Boolean = false
private var isManagedProfileAvailable: Boolean? = null

override val name: Int
get() = R.string.sensor_name_device_policy
Expand Down Expand Up @@ -56,12 +56,14 @@ class DevicePolicyManager : SensorManager {
return
}

onSensorUpdated(
context,
isWorkProfile,
isManagedProfileAvailable,
isWorkProfile.statelessIcon,
mapOf()
)
isManagedProfileAvailable?.let { state ->
onSensorUpdated(
context,
isWorkProfile,
state,
isWorkProfile.statelessIcon,
mapOf()
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NotificationSensorManager : NotificationListenerService(), SensorManager {
commonR.string.sensor_description_last_notification,
"mdi:bell-ring",
docsLink = "https://companion.home-assistant.io/docs/core/sensors#last-notification",
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.INTENT_ONLY
)
val lastRemovedNotification = SensorManager.BasicSensor(
"last_removed_notification",
Expand All @@ -46,7 +46,7 @@ class NotificationSensorManager : NotificationListenerService(), SensorManager {
commonR.string.sensor_description_last_removed_notification,
"mdi:bell-ring",
docsLink = "https://companion.home-assistant.io/docs/core/sensors#last-removed-notification",
updateType = SensorManager.BasicSensor.UpdateType.INTENT
updateType = SensorManager.BasicSensor.UpdateType.INTENT_ONLY
)
val activeNotificationCount = SensorManager.BasicSensor(
"active_notification_count",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fun SensorDetailView(
text = stringResource(
when (viewModel.basicSensor.updateType) {
SensorManager.BasicSensor.UpdateType.INTENT -> commonR.string.sensor_update_type_chip_intent
SensorManager.BasicSensor.UpdateType.INTENT_ONLY -> commonR.string.sensor_update_type_chip_intent_only
SensorManager.BasicSensor.UpdateType.WORKER -> {
when (viewModel.settingUpdateFrequency) {
SensorUpdateFrequencySetting.FAST_ALWAYS -> commonR.string.sensor_update_type_chip_worker_fast_always
Expand Down Expand Up @@ -577,6 +578,9 @@ fun SensorDetailUpdateInfoDialog(
content = {
var infoString = when (basicSensor.updateType) {
SensorManager.BasicSensor.UpdateType.INTENT -> stringResource(commonR.string.sensor_update_type_info_intent)
SensorManager.BasicSensor.UpdateType.INTENT_ONLY -> {
"${stringResource(commonR.string.sensor_update_type_info_intent)}\n\n${stringResource(commonR.string.sensor_update_type_info_intent_only)}"
}
SensorManager.BasicSensor.UpdateType.WORKER -> {
"${stringResource(
when (userSetting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface SensorManager {
) {
enum class UpdateType {
INTENT,
INTENT_ONLY,
WORKER,
LOCATION,
CUSTOM
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@
<string name="sensor_worker_sync_missing_permissions">To enable this sensor, turn it on in the app settings</string>
<string name="sensor_update_frequency_summary">Change the frequency of updates for sensors that do not update instantly.</string>
<string name="sensor_update_type_chip_intent">Updates instantly</string>
<string name="sensor_update_type_chip_intent_only">Updates instantly, only on changes</string>
<string name="sensor_update_type_chip_worker_fast_always">Updates every minute</string>
<string name="sensor_update_type_chip_worker_fast_charging">Updates every 1 / 15 min</string>
<string name="sensor_update_type_chip_worker_normal">Updates every 15 min</string>
Expand All @@ -1099,6 +1100,7 @@
<string name="sensor_update_type_info_title">About sensor updates</string>
<string name="sensor_update_type_info_enable">Enable this sensor to send updates to Home Assistant.\n\n</string>
<string name="sensor_update_type_info_intent">This sensor is updated instantly whenever the state changes.</string>
<string name="sensor_update_type_info_intent_only">Note: the sensor can only listen for changes, it cannot get the current state. If the state changes when the device is restarted or while the app is not running, the sensor may not have the correct state.</string>
<string name="sensor_update_type_info_worker_fast_always">This sensor\'s state is updated every minute and when a sensor that updates instantly is updated.</string>
<string name="sensor_update_type_info_worker_fast_charging">This sensor\'s state is updated every minute while charging, every 15 minutes when not charging, and when a sensor that updates instantly is updated.</string>
<string name="sensor_update_type_info_worker_normal">This sensor\'s state is updated every 15 minutes and when a sensor that updates instantly is updated.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class WetModeSensorManager : SensorManager {
commonR.string.sensor_description_wet_mode,
"mdi:water-off",
entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC,
updateType = SensorManager.BasicSensor.UpdateType.INTENT

updateType = SensorManager.BasicSensor.UpdateType.INTENT_ONLY
)
}

Expand Down