diff --git a/custom_components/ds_air/ds_air_service/dao.py b/custom_components/ds_air/ds_air_service/dao.py index 6fc6dd1..d1076e0 100644 --- a/custom_components/ds_air/ds_air_service/dao.py +++ b/custom_components/ds_air/ds_air_service/dao.py @@ -89,6 +89,8 @@ class Sensor(Device): "humidity_lower", "pm25_upper", "pm25_lower", "co2_upper", "co2_lower", "voc_lower", "tvoc_upper", "hcho_upper", "connected", "sleep_mode_count", "time_millis"] + UNINITIALIZED_VALUE = -1000 + def __init__(self): Device.__init__(self) self.mac: str = '' diff --git a/custom_components/ds_air/ds_air_service/decoder.py b/custom_components/ds_air/ds_air_service/decoder.py index d49d180..fbba110 100644 --- a/custom_components/ds_air/ds_air_service/decoder.py +++ b/custom_components/ds_air/ds_air_service/decoder.py @@ -185,24 +185,24 @@ def load_bytes(self, b): sensor.name = sensor.alias sensor.type1 = d.read1() sensor.type2 = d.read1() - humidity = -10000 - hcho = -1000 - temp = -1000 + humidity = Sensor.UNINITIALIZED_VALUE + hcho = Sensor.UNINITIALIZED_VALUE + temp = Sensor.UNINITIALIZED_VALUE if (sensor.type1 & 1) == 1: temp = d.read2() if ((sensor.type1 >> 1) & 1) == 1: humidity = d.read2() - pm25 = -1000 + pm25 = Sensor.UNINITIALIZED_VALUE if (sensor.type1 >> 2) & 1 == 1: pm25 = d.read2() - co2 = -1000 + co2 = Sensor.UNINITIALIZED_VALUE if (sensor.type1 >> 3) & 1 == 1: co2 = d.read2() voc = EnumSensor.Voc.STEP_UNUSE if (sensor.type1 >> 4) & 1 == 1: f = d.read1() voc = EnumSensor.Voc(f) - tvoc = -1000 + tvoc = Sensor.UNINITIALIZED_VALUE if (sensor.type1 >> 5) & 1 == 1: tvoc = d.read2() if (sensor.type1 >> 6) & 1 == 1: diff --git a/custom_components/ds_air/ds_air_service/service.py b/custom_components/ds_air/ds_air_service/service.py index 677d74a..b55c854 100644 --- a/custom_components/ds_air/ds_air_service/service.py +++ b/custom_components/ds_air/ds_air_service/service.py @@ -121,8 +121,6 @@ def run(self) -> None: if cnt == 5: cnt = 0 Service.poll_status() - p = Sensor2InfoParam() - Service.send_msg(p) time.sleep(60) @@ -274,7 +272,6 @@ def set_sensors_status(sensors: typing.List[Sensor]): func(newSensor) except Exception as e: _log(str(e)) - break @staticmethod def poll_status(): diff --git a/custom_components/ds_air/manifest.json b/custom_components/ds_air/manifest.json index 1704a6c..5bf5388 100644 --- a/custom_components/ds_air/manifest.json +++ b/custom_components/ds_air/manifest.json @@ -5,6 +5,6 @@ "dependencies": [], "codeowners": [], "requirements": [], - "version": "1.2.0", + "version": "1.2.1", "config_flow": true } diff --git a/custom_components/ds_air/sensor.py b/custom_components/ds_air/sensor.py index 6a8e700..ceff5fd 100644 --- a/custom_components/ds_air/sensor.py +++ b/custom_components/ds_air/sensor.py @@ -96,7 +96,8 @@ def state(self): def parse_data(self, device: Sensor, not_update: bool = False): """Parse data sent by gateway.""" self._is_available = device.connected and device.switch_on_off - self._state = getattr(device, self._data_key) / SENSOR_TYPES.get(self._data_key)[3] + if Sensor.UNINITIALIZED_VALUE != getattr(device, self._data_key): + self._state = getattr(device, self._data_key) / SENSOR_TYPES.get(self._data_key)[3] if not not_update: self.schedule_update_ha_state() return True