From c6b1d69173fa7828ffe0115ced11ec1ec3495954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 29 Oct 2024 17:57:08 +0100 Subject: [PATCH 1/4] Add "intent only" update type for sensor --- .../companion/android/sensors/DevicePolicyManager.kt | 2 +- .../android/settings/sensor/views/SensorDetailView.kt | 4 ++++ .../companion/android/common/sensors/SensorManager.kt | 1 + common/src/main/res/values/strings.xml | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt b/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt index ed6ee28813e..4c02ed4bd44 100644 --- a/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt +++ b/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt @@ -15,7 +15,7 @@ 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 ) } diff --git a/app/src/main/java/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt b/app/src/main/java/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt index fcf60ec00a3..f94d3c01538 100644 --- a/app/src/main/java/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt +++ b/app/src/main/java/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt @@ -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 @@ -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) { diff --git a/common/src/main/java/io/homeassistant/companion/android/common/sensors/SensorManager.kt b/common/src/main/java/io/homeassistant/companion/android/common/sensors/SensorManager.kt index e64edda0bf6..7105ec05cd5 100644 --- a/common/src/main/java/io/homeassistant/companion/android/common/sensors/SensorManager.kt +++ b/common/src/main/java/io/homeassistant/companion/android/common/sensors/SensorManager.kt @@ -50,6 +50,7 @@ interface SensorManager { ) { enum class UpdateType { INTENT, + INTENT_ONLY, WORKER, LOCATION, CUSTOM diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index b0d1e66914e..59f30c2fcce 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1091,6 +1091,7 @@ To enable this sensor, turn it on in the app settings Change the frequency of updates for sensors that do not update instantly. Updates instantly + Updates instantly, only on changes Updates every minute Updates every 1 / 15 min Updates every 15 min @@ -1099,6 +1100,7 @@ About sensor updates Enable this sensor to send updates to Home Assistant.\n\n This sensor is updated instantly whenever the state changes. + Note: the sensor can only detect changes. If the state changes if the device is restarted or while the app is not running, the sensor may not have the correct state. This sensor\'s state is updated every minute and when a sensor that updates instantly is updated. 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. This sensor\'s state is updated every 15 minutes and when a sensor that updates instantly is updated. From 5b4437d3d8a5bf3475ceb12ced52da1f040c6317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 29 Oct 2024 17:59:46 +0100 Subject: [PATCH 2/4] Expand description --- common/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 59f30c2fcce..0e79349634e 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1100,7 +1100,7 @@ About sensor updates Enable this sensor to send updates to Home Assistant.\n\n This sensor is updated instantly whenever the state changes. - Note: the sensor can only detect changes. If the state changes if the device is restarted or while the app is not running, the sensor may not have the correct state. + Note: the sensor can only detect changes, it cannot read the current state. If the state changes if the device is restarted or while the app is not running, the sensor may not have the correct state. This sensor\'s state is updated every minute and when a sensor that updates instantly is updated. 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. This sensor\'s state is updated every 15 minutes and when a sensor that updates instantly is updated. From 2c8978d394e6871deb95053b45a52e246fcefa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 29 Oct 2024 18:30:50 +0100 Subject: [PATCH 3/4] Add last notification and wet mode --- .../companion/android/sensors/NotificationSensorManager.kt | 4 ++-- .../companion/android/sensors/WetModeSensorManager.kt | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/sensors/NotificationSensorManager.kt b/app/src/main/java/io/homeassistant/companion/android/sensors/NotificationSensorManager.kt index 2b4322edf3a..536e95c234c 100644 --- a/app/src/main/java/io/homeassistant/companion/android/sensors/NotificationSensorManager.kt +++ b/app/src/main/java/io/homeassistant/companion/android/sensors/NotificationSensorManager.kt @@ -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", @@ -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", diff --git a/wear/src/main/java/io/homeassistant/companion/android/sensors/WetModeSensorManager.kt b/wear/src/main/java/io/homeassistant/companion/android/sensors/WetModeSensorManager.kt index 11560b85f0d..ab4e5adb9b9 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/sensors/WetModeSensorManager.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/sensors/WetModeSensorManager.kt @@ -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 ) } From a0732b462d6dd9f8d66b69e2e563254193839173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 29 Oct 2024 18:50:31 +0100 Subject: [PATCH 4/4] Don't set default value for work profile sensor --- .../android/sensors/DevicePolicyManager.kt | 18 ++++++++++-------- common/src/main/res/values/strings.xml | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt b/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt index 4c02ed4bd44..ea75318909d 100644 --- a/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt +++ b/app/src/main/java/io/homeassistant/companion/android/sensors/DevicePolicyManager.kt @@ -23,7 +23,7 @@ class DevicePolicyManager : SensorManager { 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 @@ -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() + ) + } } } diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 0e79349634e..acb07bde108 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1100,7 +1100,7 @@ About sensor updates Enable this sensor to send updates to Home Assistant.\n\n This sensor is updated instantly whenever the state changes. - Note: the sensor can only detect changes, it cannot read the current state. If the state changes if the device is restarted or while the app is not running, the sensor may not have the correct state. + 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. This sensor\'s state is updated every minute and when a sensor that updates instantly is updated. 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. This sensor\'s state is updated every 15 minutes and when a sensor that updates instantly is updated.