From 1ed3dc3e2c6e32e385463f2b44d4bec15a45085f Mon Sep 17 00:00:00 2001 From: Necroneco Date: Mon, 21 Aug 2023 12:48:20 +0800 Subject: [PATCH] =?UTF-8?q?Change=20unit=20of=20tvoc=20to=20=C2=B5g/m?= =?UTF-8?q?=C2=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/ds_air/const.py | 2 +- custom_components/ds_air/sensor.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/ds_air/const.py b/custom_components/ds_air/const.py index 600eb71..8ca56f8 100644 --- a/custom_components/ds_air/const.py +++ b/custom_components/ds_air/const.py @@ -15,7 +15,7 @@ "humidity": [PERCENTAGE, None, SensorDeviceClass.HUMIDITY, 10], "pm25": [CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, None, SensorDeviceClass.PM25, 1], "co2": [CONCENTRATION_PARTS_PER_MILLION, None, SensorDeviceClass.CO2, 1], - "tvoc": [CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, None, SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS, 100], + "tvoc": [CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, None, SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, 0.1], "voc": [None, None, SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS, EnumSensor.Voc], "hcho": [CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, None, None, 100], } diff --git a/custom_components/ds_air/sensor.py b/custom_components/ds_air/sensor.py index d59ed49..d211b98 100644 --- a/custom_components/ds_air/sensor.py +++ b/custom_components/ds_air/sensor.py @@ -95,10 +95,11 @@ def parse_data(self, device: Sensor, not_update: bool = False): """Parse data sent by gateway.""" self._is_available = device.connected if UNINITIALIZED_VALUE != getattr(device, self._data_key): - if type(SENSOR_TYPES.get(self._data_key)[3]) != int: + scaling = SENSOR_TYPES.get(self._data_key)[3] + if type(scaling) != int and type(scaling) != float: self._state = str(getattr(device, self._data_key)) else: - self._state = getattr(device, self._data_key) / SENSOR_TYPES.get(self._data_key)[3] + self._state = getattr(device, self._data_key) / scaling if not not_update: self.schedule_update_ha_state()