2021-10-15 11:35:10 -04:00
|
|
|
from decimal import Decimal
|
2024-02-20 06:44:02 -08:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-10-15 11:35:10 -04:00
|
|
|
|
|
|
|
from .choices import WirelessChannelChoices
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'get_channel_attr',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def get_channel_attr(channel, attr):
|
|
|
|
"""
|
|
|
|
Return the specified attribute of a given WirelessChannelChoices value.
|
|
|
|
"""
|
|
|
|
if channel not in WirelessChannelChoices.values():
|
2024-02-20 06:44:02 -08:00
|
|
|
raise ValueError(_("Invalid channel value: {channel}").format(channel=channel))
|
2021-10-15 11:35:10 -04:00
|
|
|
|
|
|
|
channel_values = channel.split('-')
|
|
|
|
attrs = {
|
|
|
|
'band': channel_values[0],
|
|
|
|
'id': int(channel_values[1]),
|
|
|
|
'frequency': Decimal(channel_values[2]),
|
|
|
|
'width': Decimal(channel_values[3]),
|
|
|
|
}
|
|
|
|
if attr not in attrs:
|
2024-02-20 06:44:02 -08:00
|
|
|
raise ValueError(_("Invalid channel attribute: {name}").format(name=attr))
|
2021-10-15 11:35:10 -04:00
|
|
|
|
|
|
|
return attrs[attr]
|