Use entity class attributes for aurora (#52690)

* Use entity class attributes for aurora

* fix
This commit is contained in:
Robert Hillis 2021-07-08 09:06:00 -04:00 committed by GitHub
parent 293690e3d8
commit 922ef3f2f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 29 deletions

View File

@ -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",

View File

@ -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