From 922ef3f2f386da0210fdad1d3adbfe198c3f80ee Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 8 Jul 2021 09:06:00 -0400 Subject: [PATCH] Use entity class attributes for aurora (#52690) * Use entity class attributes for aurora * fix --- homeassistant/components/aurora/__init__.py | 30 +++++---------------- homeassistant/components/aurora/sensor.py | 7 ++--- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/aurora/__init__.py b/homeassistant/components/aurora/__init__.py index faccefda500..576ccc1275b 100644 --- a/homeassistant/components/aurora/__init__.py +++ b/homeassistant/components/aurora/__init__.py @@ -123,6 +123,8 @@ class AuroraDataUpdateCoordinator(DataUpdateCoordinator): class AuroraEntity(CoordinatorEntity): """Implementation of the base Aurora Entity.""" + _attr_extra_state_attributes = {"attribution": ATTRIBUTION} + def __init__( self, coordinator: AuroraDataUpdateCoordinator, @@ -133,35 +135,15 @@ class AuroraEntity(CoordinatorEntity): super().__init__(coordinator=coordinator) - self._name = name - self._unique_id = f"{self.coordinator.latitude}_{self.coordinator.longitude}" - self._icon = icon - - @property - def unique_id(self): - """Define the unique id based on the latitude and longitude.""" - return self._unique_id - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def extra_state_attributes(self): - """Return the state attributes.""" - return {"attribution": ATTRIBUTION} - - @property - def icon(self): - """Return the icon for the sensor.""" - return self._icon + self._attr_name = name + self._attr_unique_id = f"{coordinator.latitude}_{coordinator.longitude}" + self._attr_icon = icon @property def device_info(self): """Define the device based on name.""" return { - ATTR_IDENTIFIERS: {(DOMAIN, self._unique_id)}, + ATTR_IDENTIFIERS: {(DOMAIN, self.unique_id)}, ATTR_NAME: self.coordinator.name, ATTR_MANUFACTURER: "NOAA", ATTR_MODEL: "Aurora Visibility Sensor", diff --git a/homeassistant/components/aurora/sensor.py b/homeassistant/components/aurora/sensor.py index d7024cc630a..76be6ca97f8 100644 --- a/homeassistant/components/aurora/sensor.py +++ b/homeassistant/components/aurora/sensor.py @@ -22,12 +22,9 @@ async def async_setup_entry(hass, entry, async_add_entries): class AuroraSensor(AuroraEntity, SensorEntity): """Implementation of an aurora sensor.""" + _attr_unit_of_measurement = PERCENTAGE + @property def state(self): """Return % chance the aurora is visible.""" return self.coordinator.data - - @property - def unit_of_measurement(self): - """Return the unit of measure.""" - return PERCENTAGE