Skip to content

Commit

Permalink
Change unit of tvoc to µg/m³
Browse files Browse the repository at this point in the history
  • Loading branch information
caibinqing committed Aug 21, 2023
1 parent 097ef3f commit 1ed3dc3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/ds_air/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
5 changes: 3 additions & 2 deletions custom_components/ds_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1ed3dc3

Please sign in to comment.