Skip to content

Commit

Permalink
rename tncsettings->beaconsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
khusmann committed Dec 24, 2024
1 parent 28e264c commit 01620e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
18 changes: 9 additions & 9 deletions src/benlink/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def handle_event(event):
ChannelArgs,
Settings,
SettingsArgs,
TncSettings,
BeaconSettings,
TncSettingsArgs,
EventMessage,
SettingsChangedEvent,
Expand All @@ -161,7 +161,7 @@ class RadioClient:
_is_connected: bool = False
_conn: BleConnection
_device_info: DeviceInfo
_tnc_settings: TncSettings
_beacon_settings: BeaconSettings
_status: Status
_settings: Settings
_channels: t.List[Channel]
Expand All @@ -177,20 +177,20 @@ def __repr__(self):
return f"<{self.__class__.__name__} {self.device_uuid} (connected)>"

@property
def tnc_settings(self) -> TncSettings:
def beacon_settings(self) -> BeaconSettings:
self._assert_conn()
return self._tnc_settings
return self._beacon_settings

async def set_tnc_settings(self, **packet_settings_args: Unpack[TncSettingsArgs]):
async def set_beacon_settings(self, **packet_settings_args: Unpack[TncSettingsArgs]):
self._assert_conn()

new_packet_settings = self._tnc_settings.model_copy(
new_beacon_settings = self._beacon_settings.model_copy(
update=dict(packet_settings_args)
)

await self._conn.set_tnc_settings(new_packet_settings)
await self._conn.set_beacon_settings(new_beacon_settings)

self._tnc_settings = new_packet_settings
self._beacon_settings = new_beacon_settings

@property
def settings(self) -> Settings:
Expand Down Expand Up @@ -277,7 +277,7 @@ async def _hydrate(self) -> None:

self._settings = await self._conn.get_settings()

self._tnc_settings = await self._conn.get_tnc_settings()
self._beacon_settings = await self._conn.get_beacon_settings()

# TODO add an explicit "get status" (even though it gets set on the first event
# from enable events)
Expand Down
14 changes: 7 additions & 7 deletions src/benlink/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
RadioMessage,
MessageReplyError,
ReplyMessageT,
GetTncSettings, GetTncSettingsReply,
TncSettings,
SetTncSettings, SetTncSettingsReply,
GetBeaconSettings, GetBeaconSettingsReply,
BeaconSettings,
SetBeaconSettings, SetBeaconSettingsReply,
GetBatteryLevel, GetBatteryLevelReply,
GetBatteryLevelAsPercentage, GetBatteryLevelAsPercentageReply,
GetRCBatteryLevel, GetRCBatteryLevelReply,
Expand Down Expand Up @@ -155,16 +155,16 @@ async def send_tnc_data(self, data: bytes) -> None:
if isinstance(reply, MessageReplyError):
raise reply.as_exception()

async def get_tnc_settings(self) -> TncSettings:
async def get_beacon_settings(self) -> BeaconSettings:
"""Get the current packet settings"""
reply = await self.send_command_expect_reply(GetTncSettings(), GetTncSettingsReply)
reply = await self.send_command_expect_reply(GetBeaconSettings(), GetBeaconSettingsReply)
if isinstance(reply, MessageReplyError):
raise reply.as_exception()
return reply.tnc_settings

async def set_tnc_settings(self, packet_settings: TncSettings):
async def set_beacon_settings(self, packet_settings: BeaconSettings):
"""Set the packet settings"""
reply = await self.send_command_expect_reply(SetTncSettings(packet_settings), SetTncSettingsReply)
reply = await self.send_command_expect_reply(SetBeaconSettings(packet_settings), SetBeaconSettingsReply)
if isinstance(reply, MessageReplyError):
raise reply.as_exception()

Expand Down
38 changes: 19 additions & 19 deletions src/benlink/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def command_message_to_protocol(m: CommandMessage) -> p.Message:
tnc_data_packet=tnc_data_packet.to_protocol()
)
)
case GetTncSettings():
case GetBeaconSettings():
return p.Message(
command_group=p.CommandGroup.BASIC,
is_reply=False,
command=p.BasicCommand.READ_BSS_SETTINGS,
body=p.ReadBSSSettingsBody()
)
case SetTncSettings(packet_settings):
case SetBeaconSettings(packet_settings):
return p.Message(
command_group=p.CommandGroup.BASIC,
is_reply=False,
Expand Down Expand Up @@ -178,20 +178,20 @@ def radio_message_from_protocol(mf: p.Message) -> RadioMessage:
):
if bss_settings is None:
return MessageReplyError(
message_type=GetTncSettingsReply,
message_type=GetBeaconSettingsReply,
reason=reply_status.name,
)

return GetTncSettingsReply(TncSettings.from_protocol(bss_settings))
return GetBeaconSettingsReply(BeaconSettings.from_protocol(bss_settings))
case p.WriteBSSSettingsReplyBody(
reply_status=reply_status,
):
if reply_status != p.ReplyStatus.SUCCESS:
return MessageReplyError(
message_type=SetTncSettingsReply,
message_type=SetBeaconSettingsReply,
reason=reply_status.name,
)
return SetTncSettingsReply()
return SetBeaconSettingsReply()
case p.ReadPowerStatusReplyBody(
reply_status=reply_status,
status=power_status
Expand Down Expand Up @@ -313,12 +313,12 @@ class EnableEvents(t.NamedTuple):
pass


class GetTncSettings(t.NamedTuple):
class GetBeaconSettings(t.NamedTuple):
pass


class SetTncSettings(t.NamedTuple):
tnc_settings: TncSettings
class SetBeaconSettings(t.NamedTuple):
tnc_settings: BeaconSettings


class SetSettings(t.NamedTuple):
Expand Down Expand Up @@ -362,8 +362,8 @@ class SendTncData(t.NamedTuple):


CommandMessage = t.Union[
GetTncSettings,
SetTncSettings,
GetBeaconSettings,
SetBeaconSettings,
GetRCBatteryLevel,
GetBatteryLevelAsPercentage,
GetBatteryLevel,
Expand All @@ -385,11 +385,11 @@ class SendTncDataReply(t.NamedTuple):
pass


class GetTncSettingsReply(t.NamedTuple):
tnc_settings: TncSettings
class GetBeaconSettingsReply(t.NamedTuple):
tnc_settings: BeaconSettings


class SetTncSettingsReply(t.NamedTuple):
class SetBeaconSettingsReply(t.NamedTuple):
pass


Expand Down Expand Up @@ -450,8 +450,8 @@ def as_exception(self):


ReplyMessage = t.Union[
GetTncSettingsReply,
SetTncSettingsReply,
GetBeaconSettingsReply,
SetBeaconSettingsReply,
GetBatteryLevelAsPercentageReply,
GetRCBatteryLevelReply,
GetBatteryLevelReply,
Expand Down Expand Up @@ -960,7 +960,7 @@ class TncSettingsArgs(t.TypedDict, total=False):
aprs_callsign: str


class TncSettings(ImmutableBaseModel):
class BeaconSettings(ImmutableBaseModel):
"""A data object representing the tnc settings"""
_bss_user_id_split: t.ClassVar[IntSplit] = IntSplit(32, 32)
max_fwd_times: int
Expand All @@ -981,15 +981,15 @@ class TncSettings(ImmutableBaseModel):
aprs_callsign: str

@classmethod
def from_protocol(cls, bs: p.BSSSettingsExt | p.BSSSettings) -> TncSettings:
def from_protocol(cls, bs: p.BSSSettingsExt | p.BSSSettings) -> BeaconSettings:
"""@private (Protocol helper)"""

if not isinstance(bs, p.BSSSettingsExt):
raise ValueError(
"Radio replied with old BSSSettings message version. Upgrade your firmware!"
)

return TncSettings(
return BeaconSettings(
max_fwd_times=bs.max_fwd_times,
time_to_live=bs.time_to_live,
ptt_release_send_location=bs.ptt_release_send_location,
Expand Down

0 comments on commit 01620e8

Please sign in to comment.