diff --git a/custom_components/vesync/common.py b/custom_components/vesync/common.py index 03ccb16..1623ba1 100644 --- a/custom_components/vesync/common.py +++ b/custom_components/vesync/common.py @@ -59,6 +59,8 @@ async def async_process_devices(hass, manager): else: if hasattr(fan, "config_dict"): devices[VS_NUMBERS].append(fan) + if "air_quality" in fan.config_dict["features"]: + devices[VS_SENSORS].append(fan) devices[VS_SWITCHES].append(fan) # for automatic stop and display devices[VS_FANS].append(fan) _LOGGER.info("%d VeSync fans found", len(manager.fans)) diff --git a/custom_components/vesync/sensor.py b/custom_components/vesync/sensor.py index 5c2336c..c9db411 100644 --- a/custom_components/vesync/sensor.py +++ b/custom_components/vesync/sensor.py @@ -49,6 +49,8 @@ def _setup_entities(devices, async_add_entities): entities.extend((VeSyncPowerSensor(dev), VeSyncEnergySensor(dev))) elif is_humidifier(dev.device_type): entities.append(VeSyncHumiditySensor(dev)) + elif "air_quality" in dev.config_dict["features"]: + entities.append(VeSyncAirQualitySensor(dev)) else: _LOGGER.warning( "%s - Unknown device type - %s", dev.device_name, dev.device_type @@ -168,6 +170,40 @@ class VeSyncHumidifierSensorEntity(VeSyncBaseEntity, SensorEntity): return EntityCategory.DIAGNOSTIC +class VeSyncAirQualitySensor(VeSyncHumidifierSensorEntity): + """Representation of an air quality sensor.""" + + @property + def unique_id(self): + """Return unique ID for air quality sensor on device.""" + return f"{super().unique_id}-air-quality" + + @property + def name(self): + """Return sensor name.""" + return f"{super().name} air quality" + + @property + def device_class(self): + """Return the air quality device class.""" + return SensorDeviceClass.AQI + + @property + def native_value(self): + """Return the air quality index.""" + return self.smarthumidifier.details["air_quality_value"] + + @property + def native_unit_of_measurement(self): + """Return the % unit of measurement.""" + return " " + + @property + def state_class(self): + """Return the measurement state class.""" + return SensorStateClass.MEASUREMENT + + class VeSyncHumiditySensor(VeSyncHumidifierSensorEntity): """Representation of current humidity for a VeSync humidifier."""