Resolves #336 Replace 'unknown' state with '-'. Show displayState for badges

This commit is contained in:
estevez-dev 2019-06-23 15:24:08 +03:00
parent b63cddfa46
commit cbc56a8105
2 changed files with 7 additions and 7 deletions

View File

@ -154,7 +154,7 @@ class Entity {
entityId = rawData["entity_id"];
deviceClass = attributes["device_class"];
state = rawData["state"];
displayState = Entity.StateByDeviceClass["$deviceClass.$state"] ?? state;
displayState = Entity.StateByDeviceClass["$deviceClass.$state"] ?? (state.toLowerCase() == 'unknown' ? '-' : state);
_lastUpdated = DateTime.tryParse(rawData["last_updated"]);
entityPicture = _getEntityPictureUrl(webHost);
}

View File

@ -42,25 +42,25 @@ class BadgeWidget extends StatelessWidget {
size: iconSize,
color: Colors.black
);
onBadgeTextValue = entityModel.entityWrapper.entity.state;
onBadgeTextValue = entityModel.entityWrapper.entity.displayState;
break;
}
default:
{
double stateFontSize;
if (entityModel.entityWrapper.entity.state.length <= 3) {
if (entityModel.entityWrapper.entity.displayState.length <= 3) {
stateFontSize = 18.0;
} else if (entityModel.entityWrapper.entity.state.length <= 4) {
} else if (entityModel.entityWrapper.entity.displayState.length <= 4) {
stateFontSize = 15.0;
} else if (entityModel.entityWrapper.entity.state.length <= 6) {
} else if (entityModel.entityWrapper.entity.displayState.length <= 6) {
stateFontSize = 10.0;
} else if (entityModel.entityWrapper.entity.state.length <= 10) {
} else if (entityModel.entityWrapper.entity.displayState.length <= 10) {
stateFontSize = 8.0;
}
onBadgeTextValue = entityModel.entityWrapper.entity.unitOfMeasurement;
badgeIcon = Center(
child: Text(
"${entityModel.entityWrapper.entity.state}",
"${entityModel.entityWrapper.entity.displayState}",
overflow: TextOverflow.fade,
softWrap: false,
textAlign: TextAlign.center,