Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions homeassistant/components/xiaomi_miio/air_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

ATTR_CO2E = "carbon_dioxide_equivalent"
ATTR_TVOC = "total_volatile_organic_compounds"
ATTR_TEMP = "temperature"
ATTR_HUM = "humidity"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand All @@ -33,6 +35,8 @@
PROP_TO_ATTR = {
"carbon_dioxide_equivalent": ATTR_CO2E,
"total_volatile_organic_compounds": ATTR_TVOC,
"temperature": ATTR_TEMP,
Comment thread
fierland marked this conversation as resolved.
"humidity": ATTR_HUM,
}


Expand Down Expand Up @@ -91,6 +95,8 @@ def __init__(self, name, device, unique_id):
self._carbon_dioxide_equivalent = None
self._particulate_matter_2_5 = None
self._total_volatile_organic_compounds = None
self._temperature = None
self._humidity = None

async def async_update(self):
"""Fetch state from the miio device."""
Expand All @@ -100,6 +106,8 @@ async def async_update(self):
self._carbon_dioxide_equivalent = state.co2e
self._particulate_matter_2_5 = round(state.pm25, 1)
self._total_volatile_organic_compounds = round(state.tvoc, 3)
self._temperature = round(state.temperature, 2)
self._humidity = round(state.humidity, 2)
self._available = True
except DeviceException as ex:
self._available = False
Expand Down Expand Up @@ -150,6 +158,16 @@ def total_volatile_organic_compounds(self):
"""Return the total volatile organic compounds."""
return self._total_volatile_organic_compounds

@property
def temperature(self):
"""Return the current temperature."""
return self._temperature

@property
def humidity(self):
"""Return the current humidity."""
return self._humidity

@property
def device_state_attributes(self):
"""Return the state attributes."""
Expand Down Expand Up @@ -179,6 +197,8 @@ async def async_update(self):
self._carbon_dioxide = state.co2
self._particulate_matter_2_5 = state.pm25
self._total_volatile_organic_compounds = state.tvoc
self._temperature = state.temperature
self._humidity = state.humidity
self._available = True
except DeviceException as ex:
self._available = False
Expand Down