Improve state attributes of CityBikes (#76578)

This commit is contained in:
Franck Nijhof 2022-08-11 03:36:13 +02:00 committed by GitHub
parent 420084f6f1
commit 4c70129427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,6 @@ from homeassistant.components.sensor import (
SensorEntity, SensorEntity,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_ID, ATTR_ID,
ATTR_LATITUDE, ATTR_LATITUDE,
ATTR_LOCATION, ATTR_LOCATION,
@ -275,6 +274,7 @@ class CityBikesNetwork:
class CityBikesStation(SensorEntity): class CityBikesStation(SensorEntity):
"""CityBikes API Sensor.""" """CityBikes API Sensor."""
_attr_attribution = CITYBIKES_ATTRIBUTION
_attr_native_unit_of_measurement = "bikes" _attr_native_unit_of_measurement = "bikes"
_attr_icon = "mdi:bike" _attr_icon = "mdi:bike"
@ -292,15 +292,10 @@ class CityBikesStation(SensorEntity):
break break
self._attr_name = station_data.get(ATTR_NAME) self._attr_name = station_data.get(ATTR_NAME)
self._attr_native_value = station_data.get(ATTR_FREE_BIKES) self._attr_native_value = station_data.get(ATTR_FREE_BIKES)
self._attr_extra_state_attributes = ( self._attr_extra_state_attributes = {
{
ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION,
ATTR_UID: station_data.get(ATTR_EXTRA, {}).get(ATTR_UID), ATTR_UID: station_data.get(ATTR_EXTRA, {}).get(ATTR_UID),
ATTR_LATITUDE: station_data[ATTR_LATITUDE], ATTR_LATITUDE: station_data.get(ATTR_LATITUDE),
ATTR_LONGITUDE: station_data[ATTR_LONGITUDE], ATTR_LONGITUDE: station_data.get(ATTR_LONGITUDE),
ATTR_EMPTY_SLOTS: station_data[ATTR_EMPTY_SLOTS], ATTR_EMPTY_SLOTS: station_data.get(ATTR_EMPTY_SLOTS),
ATTR_TIMESTAMP: station_data[ATTR_TIMESTAMP], ATTR_TIMESTAMP: station_data.get(ATTR_TIMESTAMP),
} }
if station_data
else {ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION}
)