Fix TACAN beacon type import.

The dataclass contructor will not automatically convert the int in the
JSON file to the enum type, so our enum equivalence check was not
actually working, and could result in us re-allocating a TACAN channel
that was used by the map.

Fixing this problem surfaces a latent bug, where we can't actually treat
duplicate map TACAN channels as a bug because some channels are used by
multiple airports in PG.
This commit is contained in:
Dan Albert 2022-09-27 18:08:49 -07:00
parent 2461a66ad8
commit 08abe36443
3 changed files with 9 additions and 17 deletions

View File

@ -84,7 +84,13 @@ class Beacons:
beacons = {}
for bid, beacon in json.loads(beacons_file.read_text()).items():
beacons[bid] = Beacon(**beacon)
beacons[bid] = Beacon(
name=beacon["name"],
callsign=beacon["callsign"],
beacon_type=BeaconType(beacon["beacon_type"]),
hertz=beacon["hertz"],
channel=beacon["channel"],
)
cls._by_terrain[theater.terrain.name] = beacons
@classmethod

View File

@ -66,13 +66,6 @@ class OutOfTacanChannelsError(RuntimeError):
super().__init__(f"No available channels in TACAN {band.value} band")
class TacanChannelInUseError(RuntimeError):
"""Raised when attempting to reserve an in-use channel."""
def __init__(self, channel: TacanChannel) -> None:
super().__init__(f"{channel} is already in use")
class TacanRegistry:
"""Manages allocation of TACAN channels."""
@ -116,10 +109,5 @@ class TacanRegistry:
Args:
channel: The channel to reserve.
Raises:
TacanChannelInUseError: The given channel is already in use.
"""
if channel in self.allocated_channels:
raise TacanChannelInUseError(channel)
self.allocated_channels.add(channel)

View File

@ -4,7 +4,6 @@ from game.radio.tacan import (
OutOfTacanChannelsError,
TacanBand,
TacanChannel,
TacanChannelInUseError,
TacanRegistry,
TacanUsage,
)
@ -72,9 +71,8 @@ def test_reserve_all_valid_a2a() -> None:
def test_reserve_again() -> None:
registry = TacanRegistry()
with pytest.raises(TacanChannelInUseError):
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
def test_tacan_parsing() -> None: