55from datetime import UTC , datetime as dt , timedelta as td
66import importlib
77import logging
8+ import math
89import random
910from typing import Any
1011from unittest .mock import MagicMock , Mock , patch
@@ -465,7 +466,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None:
465466 await stick .disconnect ()
466467 assert not stick .network_state
467468 with pytest .raises (pw_exceptions .StickError ):
468- assert stick .mac_stick
469+ stick .mac_stick
469470
470471 async def disconnected (self , event : pw_api .StickEvent ) -> None : # type: ignore[name-defined]
471472 """Handle disconnect event callback."""
@@ -611,17 +612,17 @@ async def test_stick_node_discovered_subscription( # noqa: PLR0915
611612
612613 # Check Scan is raising NodeError for unsupported features
613614 with pytest .raises (pw_exceptions .FeatureError ):
614- assert stick .nodes ["5555555555555555" ].relay
615+ stick .nodes ["5555555555555555" ].relay
615616 with pytest .raises (pw_exceptions .FeatureError ):
616- assert stick .nodes ["5555555555555555" ].relay_state
617+ stick .nodes ["5555555555555555" ].relay_state
617618 with pytest .raises (pw_exceptions .FeatureError ):
618- assert stick .nodes ["5555555555555555" ].switch
619+ stick .nodes ["5555555555555555" ].switch
619620 with pytest .raises (pw_exceptions .FeatureError ):
620- assert stick .nodes ["5555555555555555" ].power
621+ stick .nodes ["5555555555555555" ].power
621622 with pytest .raises (pw_exceptions .FeatureError ):
622- assert stick .nodes ["5555555555555555" ].sense
623+ stick .nodes ["5555555555555555" ].sense
623624 with pytest .raises (pw_exceptions .FeatureError ):
624- assert stick .nodes ["5555555555555555" ].energy
625+ stick .nodes ["5555555555555555" ].energy
625626
626627 # Motion
627628 self .test_motion_on = asyncio .Future ()
@@ -851,11 +852,11 @@ async def test_node_relay_and_power(self, monkeypatch: pytest.MonkeyPatch) -> No
851852
852853 # Check Circle is raising NodeError for unsupported features
853854 with pytest .raises (pw_exceptions .FeatureError ):
854- assert stick .nodes ["0098765432101234" ].motion
855+ stick .nodes ["0098765432101234" ].motion
855856 with pytest .raises (pw_exceptions .FeatureError ):
856- assert stick .nodes ["0098765432101234" ].switch
857+ stick .nodes ["0098765432101234" ].switch
857858 with pytest .raises (pw_exceptions .FeatureError ):
858- assert stick .nodes ["0098765432101234" ].sense
859+ stick .nodes ["0098765432101234" ].sense
859860
860861 # Test relay init
861862 # load node 2222222222222222 which has
@@ -931,7 +932,9 @@ async def fake_get_missing_energy_logs(address: int) -> None:
931932 last_second = None , last_8_seconds = None , timestamp = None
932933 )
933934 pu = await stick .nodes ["0098765432101234" ].power_update ()
934- assert pu .last_second == 21.2780505980402
935+ assert math .isclose (
936+ pu .last_second , 21.2780505980402 , rel_tol = 1e-09 , abs_tol = 1e-09
937+ )
935938 assert pu .last_8_seconds == - 27.150578775440106
936939
937940 # Test energy state without request
@@ -1392,7 +1395,12 @@ def test_energy_counter(self) -> None:
13921395 0.07204743061527973 ,
13931396 reset_timestamp ,
13941397 )
1395- assert energy_counter_init .energy == 0.07204743061527973
1398+ assert math .isclose (
1399+ energy_counter_init .energy ,
1400+ 0.07204743061527973 ,
1401+ rel_tol = 1e-09 ,
1402+ abs_tol = 1e-09 ,
1403+ )
13961404 assert energy_counter_init .last_reset == reset_timestamp
13971405 assert energy_counter_init .last_update == reset_timestamp + td (minutes = 10 )
13981406
@@ -1401,7 +1409,12 @@ def test_energy_counter(self) -> None:
14011409 0.08263379198066137 ,
14021410 reset_timestamp ,
14031411 )
1404- assert energy_counter_init .energy == 0.08263379198066137
1412+ assert math .isclose (
1413+ energy_counter_init .energy ,
1414+ 0.08263379198066137 ,
1415+ rel_tol = 1e-09 ,
1416+ abs_tol = 1e-09 ,
1417+ )
14051418 assert energy_counter_init .last_reset == reset_timestamp
14061419 assert energy_counter_init .last_update == reset_timestamp + td (
14071420 minutes = 15 , seconds = 10
0 commit comments