From d96aec19c356ec74d520e291f9765a70ae145730 Mon Sep 17 00:00:00 2001 From: Jordan Harrison <76656637+jouwdan@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:22:44 +0100 Subject: [PATCH] test: add test for tampered sensor --- tests/test_sensor.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 1bdeb38..5752e6d 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -14,6 +14,14 @@ "inputState": 1, } +# Mock tampered sensor data for HKCSensor to process +mock_tampered_sensor_data = { + "inputId": "2", + "description": "Front Door", + "timestamp": "2024-09-02T12:00:00Z", + "inputState": 2, +} + class MockCoordinator: async_request_refresh = AsyncMock() @@ -40,6 +48,22 @@ async def test_hkc_sensor_state(hass, aioclient_mock): sensor.state == "Open" ) # as per your logic, inputState being 1 should result in state "Open" +@pytest.mark.asyncio +async def test_hkc_sensor_tampered_state(hass, aioclient_mock): + with patch.object(HKCSensor, "_panel_data", {"display": "Thu 26 Oct 10:35"}): + mock_coordinator = MockCoordinator() + sensor = HKCSensor( + "hkc_alarm_instance", mock_tampered_sensor_data, mock_coordinator + ) + await sensor.async_update() + + print(f"Mock Sensor Data: {mock_sensor_data}") + print(f"Sensor State: {sensor.state}") + + assert ( + sensor.state == "Tamper" + ) # as per your logic, inputState being 2 should result in state "Tamper" + @pytest.mark.asyncio async def test_hkc_sensor_invalid_timestamp(hass, aioclient_mock):