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

Android Auto: Set icon color when entity is considered in an active state #3805

Merged
merged 5 commits into from
Aug 24, 2023
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 @@ -24,11 +24,13 @@ 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
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
Expand Down Expand Up @@ -212,7 +214,16 @@ class EntityGridVehicleScreen(
sizeDp = 64
}.toAndroidIconCompat()
)
.setTint(CarColor.DEFAULT)
.setTint(
if (entity.isActive() && entity.domain in EntityExt.STATE_COLORED_DOMAINS) {
CarColor.createCustom(
carContext.getColor(R.color.colorYellow),
carContext.getColor(R.color.colorYellow)
)
} else {
CarColor.DEFAULT
}
)
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ 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
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
Expand Down Expand Up @@ -103,7 +105,16 @@ class MapVehicleScreen(
sizeDp = 64
}.toAndroidIconCompat()
)
.setTint(CarColor.DEFAULT)
.setTint(
if (pair.first.isActive() && pair.first.domain in EntityExt.STATE_COLORED_DOMAINS) {
CarColor.createCustom(
carContext.getColor(R.color.colorYellow),
carContext.getColor(R.color.colorYellow)
)
} else {
CarColor.DEFAULT
}
)
.build()
)
.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> Entity<T>.domain: String
Expand Down Expand Up @@ -746,3 +778,23 @@ fun <T> Entity<T>.isExecuting() = when (state) {
"unlocking" -> true
else -> false
}

fun <T> Entity<T>.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
}
1 change: 1 addition & 0 deletions common/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<color name="colorAlertWarning">#1fffa600</color>
<color name="colorOnAlertWarning">#ffa600</color>
<color name="colorDeviceControlsLightOn">#FDD663</color>
<color name="colorYellow">#F6C344</color>
<color name="colorDeviceControlsOff">#9AA0A6</color>
<color name="colorDeviceControlsDefaultOn">#8AB4F8</color>
<color name="colorDeviceControlsThermostatHeat">#FF8B66</color>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down