Skip to content

Commit

Permalink
Merge pull request #30 from jouwdan/fix/29-add-input-states
Browse files Browse the repository at this point in the history
fix(29): Add input states for tamper & inhibited
  • Loading branch information
jasonmadigan authored Sep 17, 2024
2 parents fe3aa32 + d96aec1 commit 30b4f7f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 30b4f7f

Please sign in to comment.