Skip to content

Commit

Permalink
Prevent entity ID typos throwing errors (#3829)
Browse files Browse the repository at this point in the history
Prevent typos throwing errors for more info panel
  • Loading branch information
jpelgrom authored Aug 29, 2023
1 parent 02160c4 commit a9b7dfd
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a9b7dfd

Please sign in to comment.