Skip to content

Commit

Permalink
Add more domains to device control support (#4922)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshokouhi authored Dec 23, 2024
1 parent df17ad9 commit 7f06015
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -38,7 +39,11 @@ object DefaultSliderControl : HaControl {
DeviceTypes.TYPE_UNKNOWN

override fun getDomainString(context: Context, entity: Entity<Map<String, Any>>): 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ object DefaultSwitchControl : HaControl {

override fun getDeviceType(entity: Entity<Map<String, Any>>): 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
}

override fun getDomainString(context: Context, entity: Entity<Map<String, Any>>): 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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,49 @@ fun <T> Entity<T>.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
Expand All @@ -470,7 +512,11 @@ fun <T> Entity<T>.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
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1351,4 +1351,8 @@
<string name="sensor_description_hydration">Total hydration in milliliters since midnight from Health Connect</string>
<string name="basic_sensor_name_resting_heart_rate">Resting heart rate</string>
<string name="sensor_description_resting_heart_rate">Last recorded resting heart rate from Health Connect</string>
<string name="domain_number">Number</string>
<string name="domain_remote">Remote</string>
<string name="domain_siren">Siren</string>
<string name="domain_humidifier">Humidifier</string>
</resources>

0 comments on commit 7f06015

Please sign in to comment.