From 7f06015a3f512ba102dd4bae5467f094f3fcce2e Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Mon, 23 Dec 2024 09:59:28 -0800 Subject: [PATCH] Add more domains to device control support (#4922) --- .../android/controls/DefaultSliderControl.kt | 7 ++- .../android/controls/DefaultSwitchControl.kt | 6 +++ .../companion/android/controls/HaControl.kt | 5 +- .../controls/HaControlsProviderService.kt | 5 +- .../android/common/data/integration/Entity.kt | 50 ++++++++++++++++++- common/src/main/res/values/strings.xml | 4 ++ 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSliderControl.kt b/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSliderControl.kt index 2bdc1b62992..efccfaad280 100644 --- a/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSliderControl.kt +++ b/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSliderControl.kt @@ -11,6 +11,7 @@ import androidx.annotation.RequiresApi import io.homeassistant.companion.android.common.R as commonR import io.homeassistant.companion.android.common.data.integration.Entity import io.homeassistant.companion.android.common.data.integration.IntegrationRepository +import io.homeassistant.companion.android.common.data.integration.domain @RequiresApi(Build.VERSION_CODES.R) object DefaultSliderControl : HaControl { @@ -38,7 +39,11 @@ object DefaultSliderControl : HaControl { DeviceTypes.TYPE_UNKNOWN override fun getDomainString(context: Context, entity: Entity>): String = - context.getString(commonR.string.domain_input_number) + if (entity.domain == "input_number") { + context.getString(commonR.string.domain_input_number) + } else { + context.getString(commonR.string.domain_number) + } override suspend fun performAction( integrationRepository: IntegrationRepository, diff --git a/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSwitchControl.kt b/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSwitchControl.kt index 37ed4db4245..bfb35d2449b 100644 --- a/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSwitchControl.kt +++ b/app/src/main/java/io/homeassistant/companion/android/controls/DefaultSwitchControl.kt @@ -39,6 +39,9 @@ object DefaultSwitchControl : HaControl { override fun getDeviceType(entity: Entity>): Int = when (entity.domain) { + "humidifier" -> DeviceTypes.TYPE_HUMIDIFIER + "remote" -> DeviceTypes.TYPE_REMOTE_CONTROL + "siren" -> DeviceTypes.TYPE_SECURITY_SYSTEM "switch" -> DeviceTypes.TYPE_SWITCH else -> DeviceTypes.TYPE_GENERIC_ON_OFF } @@ -46,7 +49,10 @@ object DefaultSwitchControl : HaControl { override fun getDomainString(context: Context, entity: Entity>): String = when (entity.domain) { "automation" -> context.getString(commonR.string.domain_automation) + "humidifier" -> context.getString(commonR.string.domain_humidifier) "input_boolean" -> context.getString(commonR.string.domain_input_boolean) + "remote" -> context.getString(commonR.string.domain_remote) + "siren" -> context.getString(commonR.string.domain_siren) "switch" -> context.getString(commonR.string.domain_switch) else -> entity.domain.capitalize(Locale.getDefault()) } diff --git a/app/src/main/java/io/homeassistant/companion/android/controls/HaControl.kt b/app/src/main/java/io/homeassistant/companion/android/controls/HaControl.kt index 5e815638b19..2a50eef990b 100644 --- a/app/src/main/java/io/homeassistant/companion/android/controls/HaControl.kt +++ b/app/src/main/java/io/homeassistant/companion/android/controls/HaControl.kt @@ -77,8 +77,9 @@ interface HaControl { control.setCustomIcon(iconDrawable.toAndroidIconCompat().toIcon(context)) } } else { - // Specific override for media_player icons to match HA frontend rather than provided device type - if (entity.domain == "media_player") { + // Specific override for some domain icons to match HA frontend rather than provided device type + val iconOverride = listOf("media_player", "number") + if (entity.domain in iconOverride) { val icon = IconicsDrawable(context, entity.getIcon(context)).apply { sizeDp = 48 } val tint = if (entity.isActive()) R.color.colorDeviceControlsDefaultOn else R.color.colorDeviceControlsOff icon.setTint(ContextCompat.getColor(context, tint)) diff --git a/app/src/main/java/io/homeassistant/companion/android/controls/HaControlsProviderService.kt b/app/src/main/java/io/homeassistant/companion/android/controls/HaControlsProviderService.kt index 45a799b79eb..1b2a70adefc 100644 --- a/app/src/main/java/io/homeassistant/companion/android/controls/HaControlsProviderService.kt +++ b/app/src/main/java/io/homeassistant/companion/android/controls/HaControlsProviderService.kt @@ -48,15 +48,18 @@ class HaControlsProviderService : ControlsProviderService() { "cover" to CoverControl, "fan" to FanControl, "ha_failed" to HaFailedControl, + "humidifier" to DefaultSwitchControl, "input_boolean" to DefaultSwitchControl, "input_button" to DefaultButtonControl, "input_number" to DefaultSliderControl, "light" to LightControl, "lock" to LockControl, "media_player" to MediaPlayerControl, - "remote" to null, + "number" to DefaultSliderControl, + "remote" to DefaultSwitchControl, "scene" to DefaultButtonControl, "script" to DefaultButtonControl, + "siren" to DefaultSwitchControl, "switch" to DefaultSwitchControl, "vacuum" to VacuumControl ) 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 047b03fa289..0a9604fe6b6 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 @@ -461,7 +461,49 @@ fun Entity.getIcon(context: Context): IIcon { } } "notify" -> CommunityMaterial.Icon3.cmd_message - "number" -> CommunityMaterial.Icon3.cmd_ray_vertex + "number" -> when (attributes["device_class"]) { + "apparent_power", "power", "reactive_power" -> CommunityMaterial.Icon2.cmd_flash + "aqi" -> CommunityMaterial.Icon.cmd_air_filter + "area" -> CommunityMaterial.Icon3.cmd_texture_box + "atmospheric_pressure" -> CommunityMaterial.Icon3.cmd_thermometer_lines + "battery" -> CommunityMaterial.Icon.cmd_battery + "blood_glucose_concentration" -> CommunityMaterial.Icon3.cmd_spoon_sugar + "carbon_dioxide" -> CommunityMaterial.Icon3.cmd_molecule_co2 + "carbon_monoxide" -> CommunityMaterial.Icon3.cmd_molecule_co + "conductivity" -> CommunityMaterial.Icon3.cmd_sprout_outline + "current" -> CommunityMaterial.Icon.cmd_current_ac + "data_rate" -> CommunityMaterial.Icon3.cmd_transmission_tower + "data_size" -> CommunityMaterial.Icon.cmd_database + "distance" -> CommunityMaterial.Icon.cmd_arrow_left_right + "duration" -> CommunityMaterial.Icon3.cmd_progress_clock + "energy" -> CommunityMaterial.Icon2.cmd_lightning_bolt + "energy_storage" -> CommunityMaterial.Icon.cmd_car_battery + "frequency", "voltage" -> CommunityMaterial.Icon3.cmd_sine_wave + "gas" -> CommunityMaterial.Icon3.cmd_meter_gas + "humidity" -> CommunityMaterial.Icon3.cmd_water_percent + "illuminance" -> CommunityMaterial.Icon.cmd_brightness_5 + "irradiance" -> CommunityMaterial.Icon3.cmd_sun_wireless + "moisture" -> CommunityMaterial.Icon3.cmd_water_percent + "monetary" -> CommunityMaterial.Icon.cmd_cash + "nitrogen_dioxide", "nitrogen_monoxide", "nitrogen_oxide", "ozone", + "pm1", "pm10", "pm25", "sulfur_dioxide", "volatile_organic_compounds", + "volatile_organic_compounds_parts" -> CommunityMaterial.Icon3.cmd_molecule + "ph" -> CommunityMaterial.Icon3.cmd_ph + "power_factor" -> CommunityMaterial.Icon.cmd_angle_acute + "precipitation" -> CommunityMaterial.Icon3.cmd_weather_rainy + "precipitation_intensity" -> CommunityMaterial.Icon3.cmd_weather_pouring + "pressure" -> CommunityMaterial.Icon2.cmd_gauge + "signal_strength" -> CommunityMaterial.Icon3.cmd_wifi + "sound_pressure" -> CommunityMaterial.Icon.cmd_ear_hearing + "speed" -> CommunityMaterial.Icon3.cmd_speedometer + "temperature" -> CommunityMaterial.Icon3.cmd_thermometer + "volume" -> CommunityMaterial.Icon.cmd_car_coolant_level + "volume_storage" -> CommunityMaterial.Icon3.cmd_storage_tank + "water" -> CommunityMaterial.Icon3.cmd_water + "weight" -> CommunityMaterial.Icon3.cmd_weight + "wind_speed" -> CommunityMaterial.Icon3.cmd_weather_windy + else -> CommunityMaterial.Icon3.cmd_ray_vertex + } "persistent_notification" -> CommunityMaterial.Icon.cmd_bell "person" -> if (compareState == "not_home") { CommunityMaterial.Icon.cmd_account_arrow_right @@ -470,7 +512,11 @@ fun Entity.getIcon(context: Context): IIcon { } "plant" -> CommunityMaterial.Icon2.cmd_flower "proximity" -> CommunityMaterial.Icon.cmd_apple_safari - "remote" -> CommunityMaterial.Icon3.cmd_remote + "remote" -> if (compareState == "on") { + CommunityMaterial.Icon3.cmd_remote + } else { + CommunityMaterial.Icon3.cmd_remote_off + } "scene" -> CommunityMaterial.Icon3.cmd_palette_outline // Different from frontend: outline version "schedule" -> CommunityMaterial.Icon.cmd_calendar_clock "script" -> CommunityMaterial.Icon3.cmd_script_text_outline // Different from frontend: outline version diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index e57ac6ed1d0..7001a938b5c 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1351,4 +1351,8 @@ Total hydration in milliliters since midnight from Health Connect Resting heart rate Last recorded resting heart rate from Health Connect + Number + Remote + Siren + Humidifier