Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(29): Add input states for tamper & inhibited #30

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions custom_components/hkc_alarm/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def state(self):
f"Sensor {self.name} state determined as 'Open' due to inputState being 1."
)
return "Open"
elif self._input_data["inputState"] == 2:
_logger.debug(
f"Sensor {self.name} state determined as 'Tamper' due to inputState being 2."
)
return "Tamper"
elif self._input_data["inputState"] == 5:
_logger.debug(
f"Sensor {self.name} state determined as 'Inhibited' due to inputState being 5."
)
return "Inhibited"
else:
_logger.debug(f"Sensor {self.name} state determined as 'Closed'.")
return "Closed"
Expand Down
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
Loading