Use shorthand attribute in Google Travel Time (#99331)

pull/99337/head
Joost Lekkerkerker 2023-08-30 15:09:02 +02:00 committed by GitHub
parent 7170f5d36c
commit 66ad605d3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 27 deletions

View File

@ -70,15 +70,21 @@ class GoogleTravelTimeSensor(SensorEntity):
"""Representation of a Google travel time sensor."""
_attr_attribution = ATTRIBUTION
_attr_native_unit_of_measurement = UnitOfTime.MINUTES
def __init__(self, config_entry, name, api_key, origin, destination, client):
"""Initialize the sensor."""
self._name = name
self._attr_name = name
self._attr_unique_id = config_entry.entry_id
self._attr_device_info = DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, api_key)},
name=DOMAIN,
)
self._config_entry = config_entry
self._unit_of_measurement = UnitOfTime.MINUTES
self._matrix = None
self._api_key = api_key
self._unique_id = config_entry.entry_id
self._client = client
self._origin = origin
self._destination = destination
@ -107,25 +113,6 @@ class GoogleTravelTimeSensor(SensorEntity):
return round(_data["duration"]["value"] / 60)
return None
@property
def device_info(self) -> DeviceInfo:
"""Return device specific attributes."""
return DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, self._api_key)},
name=DOMAIN,
)
@property
def unique_id(self) -> str:
"""Return unique ID of entity."""
return self._unique_id
@property
def name(self):
"""Get the name of the sensor."""
return self._name
@property
def extra_state_attributes(self):
"""Return the state attributes."""
@ -147,11 +134,6 @@ class GoogleTravelTimeSensor(SensorEntity):
res["destination"] = self._resolved_destination
return res
@property
def native_unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
async def first_update(self, _=None):
"""Run the first update and write the state."""
await self.hass.async_add_executor_job(self.update)