Skip to content

Commit

Permalink
feat: Check firmware version from temperature report (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmroche committed Mar 6, 2022
1 parent 1bf2462 commit cd6a25f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
29 changes: 19 additions & 10 deletions greeclimate/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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"""
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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")
Expand Down

0 comments on commit cd6a25f

Please sign in to comment.