Add unit_of_measurement property for air_quality entity (#33304)
This commit is contained in:
parent
f3b702db5a
commit
c30600a044
3 changed files with 14 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
from homeassistant.helpers.config_validation import ( # noqa: F401
|
||||
PLATFORM_SCHEMA,
|
||||
PLATFORM_SCHEMA_BASE,
|
||||
|
@ -144,3 +145,8 @@ class AirQualityEntity(Entity):
|
|||
def state(self):
|
||||
"""Return the current state."""
|
||||
return self.particulate_matter_2_5
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
|
|
|
@ -5,12 +5,7 @@ from miio import AirQualityMonitor, Device, DeviceException
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.air_quality import PLATFORM_SCHEMA, AirQualityEntity
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.exceptions import NoEntitySpecifiedError, PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
|
@ -93,7 +88,6 @@ class AirMonitorB1(AirQualityEntity):
|
|||
self._device = device
|
||||
self._unique_id = unique_id
|
||||
self._icon = "mdi:cloud"
|
||||
self._unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
self._available = None
|
||||
self._air_quality_index = None
|
||||
self._carbon_dioxide = None
|
||||
|
@ -185,11 +179,6 @@ class AirMonitorB1(AirQualityEntity):
|
|||
|
||||
return data
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
||||
class AirMonitorS1(AirMonitorB1):
|
||||
"""Air Quality class for Xiaomi cgllc.airmonitor.s1 device."""
|
||||
|
|
|
@ -5,6 +5,10 @@ from homeassistant.components.air_quality import (
|
|||
ATTR_OZONE,
|
||||
ATTR_PM_10,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
|
@ -34,3 +38,6 @@ async def test_attributes(hass):
|
|||
assert data.get(ATTR_N2O) is None
|
||||
assert data.get(ATTR_OZONE) is None
|
||||
assert data.get(ATTR_ATTRIBUTION) == "Powered by Home Assistant"
|
||||
assert (
|
||||
data.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue