mirror of
https://github.com/home-assistant/android
synced 2024-09-19 16:11:37 +00:00
Catch the exception when we get null for attributes (#958)
* Catch the exception when we get null for attributes * Review comments * Review comments for proper fix
This commit is contained in:
parent
54a0d83c03
commit
30fd61ad6e
|
@ -125,9 +125,16 @@ class StaticWidget : AppWidgetProvider() {
|
||||||
|
|
||||||
if (attributeIds == null) return entity?.state
|
if (attributeIds == null) return entity?.state
|
||||||
|
|
||||||
val fetchedAttributes = entity?.attributes as Map<*, *>
|
var fetchedAttributes: Map<*, *>
|
||||||
val attributeValues = attributeIds.split(",").map { id -> fetchedAttributes.get(id)?.toString() }
|
var attributeValues: List<String?>
|
||||||
return entity.state.plus(if (attributeValues.isNotEmpty()) stateSeparator else "").plus(attributeValues.joinToString(attributeSeparator))
|
try {
|
||||||
|
fetchedAttributes = entity?.attributes as? Map<*, *> ?: mapOf<String, String>()
|
||||||
|
attributeValues = attributeIds.split(",").map { id -> fetchedAttributes.get(id)?.toString() }
|
||||||
|
return entity?.state.plus(if (attributeValues.isNotEmpty()) stateSeparator else "").plus(attributeValues.joinToString(attributeSeparator))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.d(TAG, "Unable to fetch entity state and attributes", e)
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
Loading…
Reference in a new issue