mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use entity class attributes for Citybikes (#53167)
* Use entity class attributes for citybikes * tweak
This commit is contained in:
parent
bf4ca2d68d
commit
3c6f0d11a6
@ -265,50 +265,32 @@ class CityBikesNetwork:
|
||||
class CityBikesStation(SensorEntity):
|
||||
"""CityBikes API Sensor."""
|
||||
|
||||
_attr_unit_of_measurement = "bikes"
|
||||
_attr_icon = "mdi:bike"
|
||||
|
||||
def __init__(self, network, station_id, entity_id):
|
||||
"""Initialize the sensor."""
|
||||
self._network = network
|
||||
self._station_id = station_id
|
||||
self._station_data = {}
|
||||
self.entity_id = entity_id
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._station_data.get(ATTR_FREE_BIKES)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._station_data.get(ATTR_NAME)
|
||||
|
||||
async def async_update(self):
|
||||
"""Update station state."""
|
||||
for station in self._network.stations:
|
||||
if station[ATTR_ID] == self._station_id:
|
||||
self._station_data = station
|
||||
station_data = station
|
||||
break
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if self._station_data:
|
||||
return {
|
||||
self._attr_name = station_data.get(ATTR_NAME)
|
||||
self._attr_state = station_data.get(ATTR_FREE_BIKES)
|
||||
self._attr_extra_state_attributes = (
|
||||
{
|
||||
ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION,
|
||||
ATTR_UID: self._station_data.get(ATTR_EXTRA, {}).get(ATTR_UID),
|
||||
ATTR_LATITUDE: self._station_data[ATTR_LATITUDE],
|
||||
ATTR_LONGITUDE: self._station_data[ATTR_LONGITUDE],
|
||||
ATTR_EMPTY_SLOTS: self._station_data[ATTR_EMPTY_SLOTS],
|
||||
ATTR_TIMESTAMP: self._station_data[ATTR_TIMESTAMP],
|
||||
ATTR_UID: station_data.get(ATTR_EXTRA, {}).get(ATTR_UID),
|
||||
ATTR_LATITUDE: station_data[ATTR_LATITUDE],
|
||||
ATTR_LONGITUDE: station_data[ATTR_LONGITUDE],
|
||||
ATTR_EMPTY_SLOTS: station_data[ATTR_EMPTY_SLOTS],
|
||||
ATTR_TIMESTAMP: station_data[ATTR_TIMESTAMP],
|
||||
}
|
||||
return {ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION}
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return "bikes"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
return "mdi:bike"
|
||||
if station_data
|
||||
else {ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION}
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user