From faafe66a1daedc5be311cd100ac565b251e8411d Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Sat, 19 Aug 2023 15:45:12 -0700 Subject: [PATCH 1/5] Android Auto: Set icon color when entity is considered in an active state --- .../android/vehicle/EntityGridVehicleScreen.kt | 12 +++++++++++- .../android/vehicle/MapVehicleScreen.kt | 12 +++++++++++- .../android/common/data/integration/Entity.kt | 18 ++++++++++++++++++ common/src/main/res/values/colors.xml | 1 + .../companion/android/theme/Color.kt | 2 +- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt index d87532c6ce9..02c7edc8f69 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt @@ -29,6 +29,7 @@ import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName import io.homeassistant.companion.android.common.data.integration.friendlyState import io.homeassistant.companion.android.common.data.integration.getIcon +import io.homeassistant.companion.android.common.data.integration.isActive import io.homeassistant.companion.android.common.data.integration.isExecuting import io.homeassistant.companion.android.common.data.integration.onPressed import io.homeassistant.companion.android.common.data.prefs.PrefsRepository @@ -212,7 +213,16 @@ class EntityGridVehicleScreen( sizeDp = 64 }.toAndroidIconCompat() ) - .setTint(CarColor.DEFAULT) + .setTint( + if (entity.isActive()) { + CarColor.createCustom( + carContext.getColor(R.color.colorYellow), + carContext.getColor(R.color.colorYellow) + ) + } else { + CarColor.DEFAULT + } + ) .build() ) } diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt index 7b0a0731fd9..cdec156f064 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt @@ -29,6 +29,7 @@ import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName import io.homeassistant.companion.android.common.data.integration.friendlyState import io.homeassistant.companion.android.common.data.integration.getIcon +import io.homeassistant.companion.android.common.data.integration.isActive import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch import io.homeassistant.companion.android.common.R as commonR @@ -103,7 +104,16 @@ class MapVehicleScreen( sizeDp = 64 }.toAndroidIconCompat() ) - .setTint(CarColor.DEFAULT) + .setTint( + if (pair.first.isActive()) { + CarColor.createCustom( + carContext.getColor(R.color.colorYellow), + carContext.getColor(R.color.colorYellow) + ) + } else { + CarColor.DEFAULT + } + ) .build() ) .setOnClickListener { diff --git a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt index a8d3e61ca1c..05eca54bd4f 100644 --- a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt +++ b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt @@ -746,3 +746,21 @@ fun Entity.isExecuting() = when (state) { "unlocking" -> true else -> false } + +fun Entity.isActive() = when { + (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" + (state == "unavailable" || state == "unknown") -> false + (state == "off" && domain != "alert") -> false + (domain == "alarm_control_panel") -> state != "disarmed" + (domain == "alert") -> state != "idle" + (domain == "cover") -> state != "closed" + (domain in listOf("device_tracker", "person")) -> state != "not_home" + (domain == "lock") -> state != "locked" + (domain == "media_player") -> state != "standby" + (domain == "vacuum") -> state !in listOf("idle", "docked", "paused") + (domain == "plant") -> state == "problem" + (domain == "group") -> state in listOf("on", "home", "open", "locked", "problem") + (domain == "timer") -> state == "active" + (domain == "camera") -> state == "streaming" + else -> true +} diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index b02635e181d..69f8f10accf 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -29,6 +29,7 @@ #1fffa600 #ffa600 #FDD663 + #F6C344 #9AA0A6 #8AB4F8 #FF8B66 diff --git a/wear/src/main/java/io/homeassistant/companion/android/theme/Color.kt b/wear/src/main/java/io/homeassistant/companion/android/theme/Color.kt index ce58654482c..b25a3d4f73b 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/theme/Color.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/theme/Color.kt @@ -5,7 +5,7 @@ import androidx.wear.compose.material.Colors val Blue = Color(0xFF03A9F4) val BlueDark = Color(0xFF0288D1) -val Yellow = Color(0xFFFDD835) +val Yellow = Color(0xFFF6C344) val Orange = Color(0xFFFF9800) val Red = Color(0xFFD32F2F) From 7bb8031c2a3a7c07f7667c2b86970d4eae9d99ee Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Tue, 22 Aug 2023 12:58:05 -0700 Subject: [PATCH 2/5] Add link to frontend code for determing active state --- .../companion/android/common/data/integration/Entity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt index 05eca54bd4f..d82971b49cc 100644 --- a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt +++ b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt @@ -748,6 +748,7 @@ fun Entity.isExecuting() = when (state) { } fun Entity.isActive() = when { + // https://github.com/home-assistant/frontend/blob/dev/src/common/entity/state_active.ts (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" (state == "unavailable" || state == "unknown") -> false (state == "off" && domain != "alert") -> false From 2be4a0da9f3c079a71c6d1feb8a6fc31d2dac912 Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Tue, 22 Aug 2023 15:47:53 -0700 Subject: [PATCH 3/5] Add lawn_mower domain and a check on supported colored domains --- .../android/common/data/integration/Entity.kt | 71 ++++++++++++++----- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt index d82971b49cc..cd622024256 100644 --- a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt +++ b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt @@ -53,6 +53,38 @@ object EntityExt { "scene", "script" ) + + val STATE_COLORED_DOMAINS = listOf( + "alarm_control_panel", + "alert", + "automation", + "binary_sensor", + "calendar", + "camera", + "climate", + "cover", + "device_tracker", + "fan", + "group", + "humidifier", + "input_boolean", + "lawn_mower", + "light", + "lock", + "media_player", + "person", + "plant", + "remote", + "schedule", + "script", + "siren", + "sun", + "switch", + "timer", + "update", + "vacuum", + "water_heater" + ) } val Entity.domain: String @@ -747,21 +779,26 @@ fun Entity.isExecuting() = when (state) { else -> false } -fun Entity.isActive() = when { - // https://github.com/home-assistant/frontend/blob/dev/src/common/entity/state_active.ts - (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" - (state == "unavailable" || state == "unknown") -> false - (state == "off" && domain != "alert") -> false - (domain == "alarm_control_panel") -> state != "disarmed" - (domain == "alert") -> state != "idle" - (domain == "cover") -> state != "closed" - (domain in listOf("device_tracker", "person")) -> state != "not_home" - (domain == "lock") -> state != "locked" - (domain == "media_player") -> state != "standby" - (domain == "vacuum") -> state !in listOf("idle", "docked", "paused") - (domain == "plant") -> state == "problem" - (domain == "group") -> state in listOf("on", "home", "open", "locked", "problem") - (domain == "timer") -> state == "active" - (domain == "camera") -> state == "streaming" - else -> true +fun Entity.isActive() = if (domain in EntityExt.STATE_COLORED_DOMAINS) { + when { + // https://github.com/home-assistant/frontend/blob/dev/src/common/entity/state_active.ts + (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" + (state == "unavailable" || state == "unknown") -> false + (state == "off" && domain != "alert") -> false + (domain == "alarm_control_panel") -> state != "disarmed" + (domain == "alert") -> state != "idle" + (domain == "cover") -> state != "closed" + (domain in listOf("device_tracker", "person")) -> state != "not_home" + (domain == "lawn_mower") -> state in listOf("mowing", "error") + (domain == "lock") -> state != "locked" + (domain == "media_player") -> state != "standby" + (domain == "vacuum") -> state !in listOf("idle", "docked", "paused") + (domain == "plant") -> state == "problem" + (domain == "group") -> state in listOf("on", "home", "open", "locked", "problem") + (domain == "timer") -> state == "active" + (domain == "camera") -> state == "streaming" + else -> true + } +} else { + false } From c780a9b2952baf69a4d0f61ada0d8aba560b817f Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Wed, 23 Aug 2023 06:46:40 -0700 Subject: [PATCH 4/5] Split up isActive and state colored domains --- .../vehicle/EntityGridVehicleScreen.kt | 3 +- .../android/common/data/integration/Entity.kt | 40 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt index 02c7edc8f69..01205b17fa9 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt @@ -24,6 +24,7 @@ import com.mikepenz.iconics.utils.sizeDp import com.mikepenz.iconics.utils.toAndroidIconCompat import io.homeassistant.companion.android.common.R import io.homeassistant.companion.android.common.data.integration.Entity +import io.homeassistant.companion.android.common.data.integration.EntityExt import io.homeassistant.companion.android.common.data.integration.IntegrationRepository import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName @@ -214,7 +215,7 @@ class EntityGridVehicleScreen( }.toAndroidIconCompat() ) .setTint( - if (entity.isActive()) { + if (entity.isActive() && entity.domain in EntityExt.STATE_COLORED_DOMAINS) { CarColor.createCustom( carContext.getColor(R.color.colorYellow), carContext.getColor(R.color.colorYellow) diff --git a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt index cd622024256..6a40382fad9 100644 --- a/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt +++ b/common/src/main/java/io/homeassistant/companion/android/common/data/integration/Entity.kt @@ -779,26 +779,22 @@ fun Entity.isExecuting() = when (state) { else -> false } -fun Entity.isActive() = if (domain in EntityExt.STATE_COLORED_DOMAINS) { - when { - // https://github.com/home-assistant/frontend/blob/dev/src/common/entity/state_active.ts - (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" - (state == "unavailable" || state == "unknown") -> false - (state == "off" && domain != "alert") -> false - (domain == "alarm_control_panel") -> state != "disarmed" - (domain == "alert") -> state != "idle" - (domain == "cover") -> state != "closed" - (domain in listOf("device_tracker", "person")) -> state != "not_home" - (domain == "lawn_mower") -> state in listOf("mowing", "error") - (domain == "lock") -> state != "locked" - (domain == "media_player") -> state != "standby" - (domain == "vacuum") -> state !in listOf("idle", "docked", "paused") - (domain == "plant") -> state == "problem" - (domain == "group") -> state in listOf("on", "home", "open", "locked", "problem") - (domain == "timer") -> state == "active" - (domain == "camera") -> state == "streaming" - else -> true - } -} else { - false +fun Entity.isActive() = when { + // https://github.com/home-assistant/frontend/blob/dev/src/common/entity/state_active.ts + (domain in listOf("button", "input_button", "event", "scene")) -> state != "unavailable" + (state == "unavailable" || state == "unknown") -> false + (state == "off" && domain != "alert") -> false + (domain == "alarm_control_panel") -> state != "disarmed" + (domain == "alert") -> state != "idle" + (domain == "cover") -> state != "closed" + (domain in listOf("device_tracker", "person")) -> state != "not_home" + (domain == "lawn_mower") -> state in listOf("mowing", "error") + (domain == "lock") -> state != "locked" + (domain == "media_player") -> state != "standby" + (domain == "vacuum") -> state !in listOf("idle", "docked", "paused") + (domain == "plant") -> state == "problem" + (domain == "group") -> state in listOf("on", "home", "open", "locked", "problem") + (domain == "timer") -> state == "active" + (domain == "camera") -> state == "streaming" + else -> true } From ec47b37d88de7902362800ad045e4abf44e4e917 Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Wed, 23 Aug 2023 08:57:43 -0700 Subject: [PATCH 5/5] Update map screen --- .../companion/android/vehicle/MapVehicleScreen.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt index cdec156f064..6214b43f264 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt @@ -24,6 +24,7 @@ import com.mikepenz.iconics.utils.sizeDp import com.mikepenz.iconics.utils.toAndroidIconCompat import io.homeassistant.companion.android.common.R import io.homeassistant.companion.android.common.data.integration.Entity +import io.homeassistant.companion.android.common.data.integration.EntityExt import io.homeassistant.companion.android.common.data.integration.IntegrationRepository import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName @@ -105,7 +106,7 @@ class MapVehicleScreen( }.toAndroidIconCompat() ) .setTint( - if (pair.first.isActive()) { + if (pair.first.isActive() && pair.first.domain in EntityExt.STATE_COLORED_DOMAINS) { CarColor.createCustom( carContext.getColor(R.color.colorYellow), carContext.getColor(R.color.colorYellow)