mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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):
|
class CityBikesStation(SensorEntity):
|
||||||
"""CityBikes API Sensor."""
|
"""CityBikes API Sensor."""
|
||||||
|
|
||||||
|
_attr_unit_of_measurement = "bikes"
|
||||||
|
_attr_icon = "mdi:bike"
|
||||||
|
|
||||||
def __init__(self, network, station_id, entity_id):
|
def __init__(self, network, station_id, entity_id):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._network = network
|
self._network = network
|
||||||
self._station_id = station_id
|
self._station_id = station_id
|
||||||
self._station_data = {}
|
|
||||||
self.entity_id = entity_id
|
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):
|
async def async_update(self):
|
||||||
"""Update station state."""
|
"""Update station state."""
|
||||||
for station in self._network.stations:
|
for station in self._network.stations:
|
||||||
if station[ATTR_ID] == self._station_id:
|
if station[ATTR_ID] == self._station_id:
|
||||||
self._station_data = station
|
station_data = station
|
||||||
break
|
break
|
||||||
|
self._attr_name = station_data.get(ATTR_NAME)
|
||||||
@property
|
self._attr_state = station_data.get(ATTR_FREE_BIKES)
|
||||||
def extra_state_attributes(self):
|
self._attr_extra_state_attributes = (
|
||||||
"""Return the state attributes."""
|
{
|
||||||
if self._station_data:
|
|
||||||
return {
|
|
||||||
ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION,
|
ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION,
|
||||||
ATTR_UID: self._station_data.get(ATTR_EXTRA, {}).get(ATTR_UID),
|
ATTR_UID: station_data.get(ATTR_EXTRA, {}).get(ATTR_UID),
|
||||||
ATTR_LATITUDE: self._station_data[ATTR_LATITUDE],
|
ATTR_LATITUDE: station_data[ATTR_LATITUDE],
|
||||||
ATTR_LONGITUDE: self._station_data[ATTR_LONGITUDE],
|
ATTR_LONGITUDE: station_data[ATTR_LONGITUDE],
|
||||||
ATTR_EMPTY_SLOTS: self._station_data[ATTR_EMPTY_SLOTS],
|
ATTR_EMPTY_SLOTS: station_data[ATTR_EMPTY_SLOTS],
|
||||||
ATTR_TIMESTAMP: self._station_data[ATTR_TIMESTAMP],
|
ATTR_TIMESTAMP: station_data[ATTR_TIMESTAMP],
|
||||||
}
|
}
|
||||||
return {ATTR_ATTRIBUTION: CITYBIKES_ATTRIBUTION}
|
if station_data
|
||||||
|
else {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"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user