From cd6a25f9556e6fd3d4871ac86883d114fc1e9b9e Mon Sep 17 00:00:00 2001 From: Clifford Roche Date: Sun, 6 Mar 2022 13:59:32 -0500 Subject: [PATCH] feat: Check firmware version from temperature report (#49) --- greeclimate/device.py | 29 +++++++++++++++++++---------- tests/test_device.py | 10 +++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/greeclimate/device.py b/greeclimate/device.py index 7856a54..cdafca6 100644 --- a/greeclimate/device.py +++ b/greeclimate/device.py @@ -91,6 +91,7 @@ def generate_temperature_record(temp_f): TEMP_MIN = 16 TEMP_MAX = 30 +TEMP_OFFSET = 40 TEMP_MIN_F = 60 TEMP_MAX_F = 86 TEMP_TABLE = [generate_temperature_record(x) for x in range(TEMP_MIN_F, TEMP_MAX_F + 1)] @@ -227,12 +228,12 @@ async def request_version(self) -> None: self.version = match and match.group(1) # Special case firmwares ... - if ( - self.hid.endswith("_JDV1.bin") - or self.hid.endswith("362001000967V2.bin") - or re.match("^.*\(MTK\)V[1-3]{1}\.bin", self.hid) # (MTK)V[1-3].bin - ): - self.version = "4.0" + # if ( + # self.hid.endswith("_JDV1.bin") + # or self.hid.endswith("362001000967V2.bin") + # or re.match("^.*\(MTK\)V[1-3]{1}\.bin", self.hid) # (MTK)V[1-3].bin + # ): + # self.version = "4.0" async def update_state(self): """Update the internal state of the device structure of the physical device""" @@ -244,12 +245,20 @@ async def update_state(self): props = [x.value for x in Props] try: - if not self.hid: - await self.request_version() - self._properties = await network.request_state( props, self.device_info, self.device_key ) + + # This check should prevent need to do version & device overrides + # to correctly compute the temperature. Though will need to confirm + # that it resolves all possible cases. + if not self.hid: + await self.request_version() + + temp = self.get_property(Props.TEMP_SENSOR) + if temp and temp <= TEMP_OFFSET: + self.version = "4.0" + except asyncio.TimeoutError: raise DeviceTimeoutError @@ -360,7 +369,7 @@ def current_temperature(self) -> int: if v == 4: return self._convert_to_units(prop, bit) elif prop != 0: - return self._convert_to_units(prop - 40, bit) + return self._convert_to_units(prop - TEMP_OFFSET, bit) return self.target_temperature diff --git a/tests/test_device.py b/tests/test_device.py index 11eaa1d..ef9676b 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -414,7 +414,14 @@ async def test_update_current_temp_unsupported(mock_request): @pytest.mark.asyncio -@pytest.mark.parametrize("temsen,hid", [(69, "362001000762+U-CS532AE(LT)V3.31.bin")]) +@pytest.mark.parametrize( + "temsen,hid", + [ + (69, "362001000762+U-CS532AE(LT)V3.31.bin"), + (61, "362001061060+U-W04HV3.29.bin"), + (62, "362001061147+U-ZX6045RV1.01.bin"), + ], +) @patch("greeclimate.network.request_state") async def test_update_current_temp_v3(mock_request, temsen, hid): """Check that properties can be updates.""" @@ -437,6 +444,7 @@ async def test_update_current_temp_v3(mock_request, temsen, hid): (21, "362001060297+U-CS532AF(MTK)V4.bin"), (21, "362001060297+U-CS532AF(MTK)V2.bin"), (22, "362001061383+U-BL3332_JDV1.bin"), + (23, "362001061217+U-W04NV7.bin"), ], ) @patch("greeclimate.network.request_state")