Prevent entity ID typos throwing errors (#3829)

Prevent typos throwing errors for more info panel
This commit is contained in:
Joris Pelgröm 2023-08-29 12:02:54 +02:00 committed by GitHub
parent 02160c4f48
commit a9b7dfdb68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1034,7 +1034,10 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
val path = intent.getStringExtra(EXTRA_PATH)
presenter.onViewReady(path)
if (path?.startsWith("entityId:") == true) {
moreInfoEntity = path.substringAfter("entityId:")
// Get the entity ID from a string formatted "entityId:domain.entity"
// https://github.com/home-assistant/core/blob/dev/homeassistant/core.py#L159
val pattern = "(?<=^entityId:)((?!.+__)(?!_)[\\da-z_]+(?<!_)\\.(?!_)[\\da-z_]+(?<!_)$)".toRegex()
moreInfoEntity = pattern.find(path)?.value ?: ""
}
intent.removeExtra(EXTRA_PATH)