diff --git a/homeassistant/components/google_travel_time/sensor.py b/homeassistant/components/google_travel_time/sensor.py index 65db01cde59..06a50dab854 100644 --- a/homeassistant/components/google_travel_time/sensor.py +++ b/homeassistant/components/google_travel_time/sensor.py @@ -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)