11"""The tests for the Modbus sensor component."""
22
3+ import math
34import struct
45
56import pytest
@@ -738,8 +739,8 @@ async def test_all_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None:
738739 [
739740 0x5102 ,
740741 0x0304 ,
741- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[0 :2 ]),
742- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[2 :4 ]),
742+ int .from_bytes (struct .pack (">f" , math . nan )[0 :2 ]),
743+ int .from_bytes (struct .pack (">f" , math . nan )[2 :4 ]),
743744 ],
744745 False ,
745746 ["34899771392.0" , STATE_UNKNOWN ],
@@ -753,8 +754,8 @@ async def test_all_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None:
753754 [
754755 0x5102 ,
755756 0x0304 ,
756- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[0 :2 ]),
757- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[2 :4 ]),
757+ int .from_bytes (struct .pack (">f" , math . nan )[0 :2 ]),
758+ int .from_bytes (struct .pack (">f" , math . nan )[2 :4 ]),
758759 ],
759760 False ,
760761 ["34899771392.0" , STATE_UNKNOWN ],
@@ -1160,8 +1161,8 @@ async def test_wrong_unpack(hass: HomeAssistant, mock_do_cycle) -> None:
11601161 CONF_DATA_TYPE : DataType .FLOAT32 ,
11611162 },
11621163 [
1163- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[0 :2 ]),
1164- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[2 :4 ]),
1164+ int .from_bytes (struct .pack (">f" , math . nan )[0 :2 ]),
1165+ int .from_bytes (struct .pack (">f" , math . nan )[2 :4 ]),
11651166 ],
11661167 STATE_UNKNOWN ,
11671168 ),
@@ -1224,8 +1225,8 @@ async def test_unpack_ok(hass: HomeAssistant, mock_do_cycle, expected) -> None:
12241225 # floats: nan, 10.600000381469727,
12251226 # 1.000879611487865e-28, 10.566553115844727
12261227 [
1227- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[0 :2 ]),
1228- int .from_bytes (struct .pack (">f" , float ( " nan" ) )[2 :4 ]),
1228+ int .from_bytes (struct .pack (">f" , math . nan )[0 :2 ]),
1229+ int .from_bytes (struct .pack (">f" , math . nan )[2 :4 ]),
12291230 0x4129 ,
12301231 0x999A ,
12311232 0x10FD ,
0 commit comments