-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow binary sensors and sensors to be added to driving favorites (#3732
) * Allow binary sensors and sensors to be added to driving favorites * Ensure sensors can still be navigated to * Review comments
- Loading branch information
Showing
7 changed files
with
88 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/io/homeassistant/companion/android/util/vehicle/DomainChecks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.homeassistant.companion.android.util.vehicle | ||
|
||
import io.homeassistant.companion.android.common.R | ||
import io.homeassistant.companion.android.common.data.integration.Entity | ||
import io.homeassistant.companion.android.common.data.integration.domain | ||
|
||
val SUPPORTED_DOMAINS_WITH_STRING = mapOf( | ||
"button" to R.string.buttons, | ||
"cover" to R.string.covers, | ||
"input_boolean" to R.string.input_booleans, | ||
"input_button" to R.string.input_buttons, | ||
"light" to R.string.lights, | ||
"lock" to R.string.locks, | ||
"scene" to R.string.scenes, | ||
"script" to R.string.scripts, | ||
"switch" to R.string.switches | ||
) | ||
val SUPPORTED_DOMAINS = SUPPORTED_DOMAINS_WITH_STRING.keys | ||
|
||
val MAP_DOMAINS = listOf( | ||
"device_tracker", | ||
"person", | ||
"sensor", | ||
"zone" | ||
) | ||
|
||
val NOT_ACTIONABLE_DOMAINS = listOf( | ||
"binary_sensor", | ||
"sensor" | ||
) | ||
|
||
fun isVehicleDomain(entity: Entity<*>): Boolean { | ||
return entity.domain in SUPPORTED_DOMAINS || | ||
entity.domain in NOT_ACTIONABLE_DOMAINS || | ||
canNavigate(entity) | ||
} | ||
|
||
fun canNavigate(entity: Entity<*>): Boolean { | ||
return ( | ||
entity.domain in MAP_DOMAINS && | ||
((entity.attributes as? Map<*, *>)?.get("latitude") as? Double != null) && | ||
((entity.attributes as? Map<*, *>)?.get("longitude") as? Double != null) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters