Skip to content

Commit

Permalink
test: add test for tampered sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
jouwdan committed Sep 2, 2024
1 parent 4e16427 commit d96aec1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit d96aec1

Please sign in to comment.