Entity State Widget bugfix (#702)

* Merge branch 'master' of F:\Colin\Projects\home-assistant-android-companion-colin-cachia with conflicts.

* Static Widget Bugfixes:
- Safely typing any attribute to String
- Removed showing of N/A when attribute not found
This commit is contained in:
Colin Cachia 2020-08-04 22:40:50 +02:00 committed by GitHub
parent d747afd37c
commit 11982f9ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -104,10 +104,11 @@ class StaticWidget : AppWidgetProvider() {
): CharSequence? {
val entity = integrationUseCase.getEntities().find { e -> e.entityId.equals(entityId) }
if (attributeId == null) return entity?.state ?: "N/A"
if (attributeId == null) return entity?.state
val fetchedAttributes = entity?.attributes as Map<String, String>
return entity.state.plus(fetchedAttributes.get(attributeId) ?: "")
val fetchedAttributes = entity?.attributes as Map<*, *>
val attributeValue = fetchedAttributes.get(attributeId)?.toString()
return entity.state.plus(if (attributeValue != null && attributeValue.isNotEmpty()) " " else "").plus(attributeValue ?: "")
}
override fun onReceive(context: Context, intent: Intent) {