Skip to content

Commit

Permalink
Add APRS object tracking (home-assistant#113080)
Browse files Browse the repository at this point in the history
* Add APRS object tracking

Closes issue home-assistant#111731

* Fix unit test

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
  • Loading branch information
PhilRW and emontnemery authored May 24, 2024
1 parent f12aee2 commit e7d23d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions homeassistant/components/aprs/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ATTR_COMMENT = "comment"
ATTR_FROM = "from"
ATTR_FORMAT = "format"
ATTR_OBJECT_NAME = "object_name"
ATTR_POS_AMBIGUITY = "posambiguity"
ATTR_SPEED = "speed"

Expand All @@ -50,7 +51,7 @@

FILTER_PORT = 14580

MSG_FORMATS = ["compressed", "uncompressed", "mic-e"]
MSG_FORMATS = ["compressed", "uncompressed", "mic-e", "object"]

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -181,7 +182,10 @@ def rx_msg(self, msg: dict[str, Any]) -> None:
"""Receive message and process if position."""
_LOGGER.debug("APRS message received: %s", str(msg))
if msg[ATTR_FORMAT] in MSG_FORMATS:
dev_id = slugify(msg[ATTR_FROM])
if msg[ATTR_FORMAT] == "object":
dev_id = slugify(msg[ATTR_OBJECT_NAME])
else:
dev_id = slugify(msg[ATTR_FROM])
lat = msg[ATTR_LATITUDE]
lon = msg[ATTR_LONGITUDE]

Expand Down
31 changes: 31 additions & 0 deletions tests/components/aprs/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,37 @@ def test_aprs_listener_rx_msg_no_position(mock_ais: MagicMock) -> None:
see.assert_not_called()


def test_aprs_listener_rx_msg_object(mock_ais: MagicMock) -> None:
"""Test rx_msg with object."""
callsign = TEST_CALLSIGN
password = TEST_PASSWORD
host = TEST_HOST
server_filter = TEST_FILTER
see = Mock()

sample_msg = aprslib.parse(
"CEEWO2-14>APLWS2,qAU,CEEWO2-15:;V4310251 *121203h5105.72N/00131.89WO085/024/A=033178!w&,!Clb=3.5m/s calibration 21% 404.40MHz Type=RS41 batt=2.7V Details on http://radiosondy.info/"
)

listener = device_tracker.AprsListenerThread(
callsign, password, host, server_filter, see
)
listener.run()
listener.rx_msg(sample_msg)

see.assert_called_with(
dev_id=device_tracker.slugify("V4310251"),
gps=(51.09534249084249, -1.5315201465201465),
attributes={
"gps_accuracy": 0,
"altitude": 10112.654400000001,
"comment": "Clb=3.5m/s calibration 21% 404.40MHz Type=RS41 batt=2.7V Details on http://radiosondy.info/",
"course": 85,
"speed": 44.448,
},
)


async def test_setup_scanner(hass: HomeAssistant) -> None:
"""Test setup_scanner."""
with patch(
Expand Down

0 comments on commit e7d23d8

Please sign in to comment.