Skip to content

Commit

Permalink
Small entity attribute cleanup in AirVisual (#51601)
Browse files Browse the repository at this point in the history
* Small entity attribute cleanup in AirVisual

* Fix icon in sensor update
  • Loading branch information
frenck committed Jun 8, 2021
1 parent a4587b5 commit 4007430
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
12 changes: 0 additions & 12 deletions homeassistant/components/airvisual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,24 +337,12 @@ def __init__(self, coordinator):
"""Initialize."""
super().__init__(coordinator)
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._icon = None
self._unit = None

@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 unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit

async def async_added_to_hass(self):
"""Register callbacks."""

Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/airvisual/air_quality.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Support for AirVisual Node/Pro units."""
from homeassistant.components.air_quality import AirQualityEntity
from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
from homeassistant.core import callback

from . import AirVisualEntity
Expand Down Expand Up @@ -34,8 +33,7 @@ def __init__(self, airvisual):
"""Initialize."""
super().__init__(airvisual)

self._icon = "mdi:chemical-weapon"
self._unit = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
self._attr_icon = "mdi:chemical-weapon"

@property
def air_quality_index(self):
Expand Down
15 changes: 6 additions & 9 deletions homeassistant/components/airvisual/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ def __init__(self, coordinator, config_entry, kind, name, icon, unit, locale):
}
)
self._config_entry = config_entry
self._icon = icon
self._kind = kind
self._locale = locale
self._name = name
self._state = None
self._unit = unit

self._attr_icon = icon
self._attr_unit_of_measurement = unit

@property
def available(self):
Expand Down Expand Up @@ -196,7 +197,7 @@ def update_from_latest_data(self):

if self._kind == SENSOR_KIND_LEVEL:
aqi = data[f"aqi{self._locale}"]
self._state, self._icon = async_get_pollutant_level_info(aqi)
self._state, self._attr_icon = async_get_pollutant_level_info(aqi)
elif self._kind == SENSOR_KIND_AQI:
self._state = data[f"aqi{self._locale}"]
elif self._kind == SENSOR_KIND_POLLUTANT:
Expand Down Expand Up @@ -244,16 +245,12 @@ def __init__(self, coordinator, kind, name, device_class, unit):
"""Initialize."""
super().__init__(coordinator)

self._device_class = device_class
self._kind = kind
self._name = name
self._state = None
self._unit = unit

@property
def device_class(self):
"""Return the device class."""
return self._device_class
self._attr_device_class = device_class
self._attr_unit_of_measurement = unit

@property
def device_info(self):
Expand Down

0 comments on commit 4007430

Please sign in to comment.