mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Use shorthand attribute in Google Travel Time (#99331)
This commit is contained in:
parent
7170f5d36c
commit
66ad605d3e
@ -70,15 +70,21 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
"""Representation of a Google travel time sensor."""
|
"""Representation of a Google travel time sensor."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_native_unit_of_measurement = UnitOfTime.MINUTES
|
||||||
|
|
||||||
def __init__(self, config_entry, name, api_key, origin, destination, client):
|
def __init__(self, config_entry, name, api_key, origin, destination, client):
|
||||||
"""Initialize the sensor."""
|
"""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._config_entry = config_entry
|
||||||
self._unit_of_measurement = UnitOfTime.MINUTES
|
|
||||||
self._matrix = None
|
self._matrix = None
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self._unique_id = config_entry.entry_id
|
|
||||||
self._client = client
|
self._client = client
|
||||||
self._origin = origin
|
self._origin = origin
|
||||||
self._destination = destination
|
self._destination = destination
|
||||||
@ -107,25 +113,6 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
return round(_data["duration"]["value"] / 60)
|
return round(_data["duration"]["value"] / 60)
|
||||||
return None
|
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
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@ -147,11 +134,6 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
res["destination"] = self._resolved_destination
|
res["destination"] = self._resolved_destination
|
||||||
return res
|
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):
|
async def first_update(self, _=None):
|
||||||
"""Run the first update and write the state."""
|
"""Run the first update and write the state."""
|
||||||
await self.hass.async_add_executor_job(self.update)
|
await self.hass.async_add_executor_job(self.update)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user