Guard against bad states in Mobile App/OwnTracks (#24292)

pull/24302/head
Paulus Schoutsen 2019-06-04 10:18:26 -07:00 committed by GitHub
parent 14c0ada9ac
commit 8b4ef3bbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -145,9 +145,9 @@ class MobileAppEntity(DeviceTrackerEntity, RestoreEntity):
attr = state.attributes
data = {
ATTR_GPS: (attr[ATTR_LATITUDE], attr[ATTR_LONGITUDE]),
ATTR_GPS_ACCURACY: attr[ATTR_GPS_ACCURACY],
ATTR_BATTERY: attr[ATTR_BATTERY_LEVEL],
ATTR_GPS: (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)),
ATTR_GPS_ACCURACY: attr.get(ATTR_GPS_ACCURACY),
ATTR_BATTERY: attr.get(ATTR_BATTERY_LEVEL),
}
data.update({key: attr[key] for key in attr if key in ATTR_KEYS})
self._data = data

View File

@ -153,10 +153,10 @@ class OwnTracksEntity(DeviceTrackerEntity, RestoreEntity):
attr = state.attributes
self._data = {
'host_name': state.name,
'gps': (attr[ATTR_LATITUDE], attr[ATTR_LONGITUDE]),
'gps_accuracy': attr[ATTR_GPS_ACCURACY],
'battery': attr[ATTR_BATTERY_LEVEL],
'source_type': attr[ATTR_SOURCE_TYPE],
'gps': (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)),
'gps_accuracy': attr.get(ATTR_GPS_ACCURACY),
'battery': attr.get(ATTR_BATTERY_LEVEL),
'source_type': attr.get(ATTR_SOURCE_TYPE),
}
@callback