2019-04-03 15:40:03 +00:00
|
|
|
"""Demo platform that offers fake air quality data."""
|
2019-01-05 16:42:36 +00:00
|
|
|
from homeassistant.components.air_quality import AirQualityEntity
|
2018-12-14 12:32:58 +00:00
|
|
|
|
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2019-01-05 16:42:36 +00:00
|
|
|
"""Set up the Air Quality."""
|
2019-11-13 15:37:31 +00:00
|
|
|
async_add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[DemoAirQuality("Home", 14, 23, 100), DemoAirQuality("Office", 4, 16, None)]
|
|
|
|
)
|
2018-12-14 12:32:58 +00:00
|
|
|
|
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Demo config entry."""
|
|
|
|
await async_setup_platform(hass, {}, async_add_entities)
|
|
|
|
|
|
|
|
|
2019-01-05 16:42:36 +00:00
|
|
|
class DemoAirQuality(AirQualityEntity):
|
|
|
|
"""Representation of Air Quality data."""
|
2018-12-14 12:32:58 +00:00
|
|
|
|
|
|
|
def __init__(self, name, pm_2_5, pm_10, n2o):
|
2019-01-05 16:42:36 +00:00
|
|
|
"""Initialize the Demo Air Quality."""
|
2018-12-14 12:32:58 +00:00
|
|
|
self._name = name
|
|
|
|
self._pm_2_5 = pm_2_5
|
|
|
|
self._pm_10 = pm_10
|
|
|
|
self._n2o = n2o
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
2020-02-24 16:47:52 +00:00
|
|
|
return f"Demo Air Quality {self._name}"
|
2018-12-14 12:32:58 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2019-01-05 16:42:36 +00:00
|
|
|
"""No polling needed for Demo Air Quality."""
|
2018-12-14 12:32:58 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def particulate_matter_2_5(self):
|
|
|
|
"""Return the particulate matter 2.5 level."""
|
|
|
|
return self._pm_2_5
|
|
|
|
|
|
|
|
@property
|
|
|
|
def particulate_matter_10(self):
|
|
|
|
"""Return the particulate matter 10 level."""
|
|
|
|
return self._pm_10
|
|
|
|
|
|
|
|
@property
|
|
|
|
def nitrogen_oxide(self):
|
|
|
|
"""Return the nitrogen oxide (N2O) level."""
|
|
|
|
return self._n2o
|
|
|
|
|
|
|
|
@property
|
|
|
|
def attribution(self):
|
|
|
|
"""Return the attribution."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return "Powered by Home Assistant"
|