Skip to content

Commit

Permalink
Merge pull request #46 from hostcc/fix/disallow-empty-device-id
Browse files Browse the repository at this point in the history
fix: Disallow storing empty device GUID
  • Loading branch information
hostcc authored Dec 16, 2024
2 parents 2aa97ea + f6b6538 commit bddb64f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pyg90alarm/device_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,12 @@ def device_id(self) -> Optional[str]:

@device_id.setter
def device_id(self, device_id: str) -> None:
# Under not yet identified circumstances the device ID might be empty
# string provided by :meth:`G90Alarm.get_host_info` - disallow that
if not device_id or len(device_id.strip()) == 0:
_LOGGER.debug(
'Device ID is empty or contains whitespace only, not setting'
)
return

self._device_id = device_id
22 changes: 22 additions & 0 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ async def test_wrong_host(
g90._handle_notification.assert_not_called()


@pytest.mark.g90device(
sent_data=[
b'ISTART[206,'
b'["","DUMMYPRODUCT",'
b'"1.2","1.1","206","206",3,3,0,2,"4242",50,100]]IEND\0',
],
)
async def test_empty_device_guid(mock_device: DeviceMock) -> None:
"""
Verifies that alert from device with empty GUID is ignored.
"""
g90 = G90Alarm(
host=mock_device.host, port=mock_device.port,
notifications_local_host=mock_device.notification_host,
notifications_local_port=mock_device.notification_port
)
# The command will fetch the host info and store the GIUD
await g90.get_host_info()
g90.close()
assert g90.device_id is None


@pytest.mark.g90device(
sent_data=[
b'ISTART[206,'
Expand Down

0 comments on commit bddb64f

Please sign in to comment.