Remove redundant property definitions in IQVIA (#52378)

This commit is contained in:
Aaron Bach 2021-07-01 00:31:46 -05:00 committed by GitHub
parent 86f46753c9
commit f98a5cc233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 43 deletions

View File

@ -104,43 +104,15 @@ class IQVIAEntity(CoordinatorEntity, SensorEntity):
def __init__(self, coordinator, entry, sensor_type, name, icon):
"""Initialize."""
super().__init__(coordinator)
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_icon = icon
self._attr_name = name
self._attr_unique_id = f"{entry.data[CONF_ZIP_CODE]}_{sensor_type}"
self._attr_unit_of_measurement = "index"
self._entry = entry
self._icon = icon
self._name = name
self._state = None
self._type = sensor_type
@property
def extra_state_attributes(self):
"""Return the device state attributes."""
return self._attrs
@property
def icon(self):
"""Return the icon."""
return self._icon
@property
def name(self):
"""Return the name."""
return self._name
@property
def state(self):
"""Return the state."""
return self._state
@property
def unique_id(self):
"""Return a unique, Home Assistant friendly identifier for this entity."""
return f"{self._entry.data[CONF_ZIP_CODE]}_{self._type}"
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return "index"
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""

View File

@ -120,7 +120,7 @@ class ForecastSensor(IQVIAEntity):
if i["minimum"] <= average <= i["maximum"]
]
self._attrs.update(
self._attr_extra_state_attributes.update(
{
ATTR_CITY: data["City"].title(),
ATTR_RATING: rating,
@ -134,10 +134,14 @@ class ForecastSensor(IQVIAEntity):
outlook_coordinator = self.hass.data[DOMAIN][DATA_COORDINATOR][
self._entry.entry_id
][TYPE_ALLERGY_OUTLOOK]
self._attrs[ATTR_OUTLOOK] = outlook_coordinator.data.get("Outlook")
self._attrs[ATTR_SEASON] = outlook_coordinator.data.get("Season")
self._attr_extra_state_attributes[
ATTR_OUTLOOK
] = outlook_coordinator.data.get("Outlook")
self._attr_extra_state_attributes[
ATTR_SEASON
] = outlook_coordinator.data.get("Season")
self._state = average
self._attr_state = average
class IndexSensor(IQVIAEntity):
@ -172,7 +176,7 @@ class IndexSensor(IQVIAEntity):
if i["minimum"] <= period["Index"] <= i["maximum"]
]
self._attrs.update(
self._attr_extra_state_attributes.update(
{
ATTR_CITY: data["City"].title(),
ATTR_RATING: rating,
@ -184,7 +188,7 @@ class IndexSensor(IQVIAEntity):
if self._type in (TYPE_ALLERGY_TODAY, TYPE_ALLERGY_TOMORROW):
for idx, attrs in enumerate(period["Triggers"]):
index = idx + 1
self._attrs.update(
self._attr_extra_state_attributes.update(
{
f"{ATTR_ALLERGEN_GENUS}_{index}": attrs["Genus"],
f"{ATTR_ALLERGEN_NAME}_{index}": attrs["Name"],
@ -194,7 +198,7 @@ class IndexSensor(IQVIAEntity):
elif self._type in (TYPE_ASTHMA_TODAY, TYPE_ASTHMA_TOMORROW):
for idx, attrs in enumerate(period["Triggers"]):
index = idx + 1
self._attrs.update(
self._attr_extra_state_attributes.update(
{
f"{ATTR_ALLERGEN_NAME}_{index}": attrs["Name"],
f"{ATTR_ALLERGEN_AMOUNT}_{index}": attrs["PPM"],
@ -202,6 +206,8 @@ class IndexSensor(IQVIAEntity):
)
elif self._type == TYPE_DISEASE_TODAY:
for attrs in period["Triggers"]:
self._attrs[f"{attrs['Name'].lower()}_index"] = attrs["Index"]
self._attr_extra_state_attributes[
f"{attrs['Name'].lower()}_index"
] = attrs["Index"]
self._state = period["Index"]
self._attr_state = period["Index"]