Use entity class attributes for Bizkaibus (#52888)

This commit is contained in:
Robert Hillis 2021-07-12 04:37:14 -04:00 committed by GitHub
parent 5d2e5d2612
commit 01afd141c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,40 +31,24 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
route = config[CONF_ROUTE]
data = Bizkaibus(stop, route)
add_entities([BizkaibusSensor(data, stop, route, name)], True)
add_entities([BizkaibusSensor(data, name)], True)
class BizkaibusSensor(SensorEntity):
"""The class for handling the data."""
def __init__(self, data, stop, route, name):
_attr_unit_of_measurement = TIME_MINUTES
def __init__(self, data, name):
"""Initialize the sensor."""
self.data = data
self.stop = stop
self.route = route
self._name = name
self._state = None
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Return the unit of measurement of the sensor."""
return TIME_MINUTES
self._attr_name = name
def update(self):
"""Get the latest data from the webservice."""
self.data.update()
with suppress(TypeError):
self._state = self.data.info[0][ATTR_DUE_IN]
self._attr_state = self.data.info[0][ATTR_DUE_IN]
class Bizkaibus: