Coverage for wireless/utils.py: 31%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from decimal import Decimal 

2 

3from django.utils.translation import gettext_lazy as _ 

4 

5from .choices import WirelessChannelChoices 

6 

7__all__ = ( 

8 'get_channel_attr', 

9) 

10 

11 

12def get_channel_attr(channel, attr): 

13 """ 

14 Return the specified attribute of a given WirelessChannelChoices value. 

15 """ 

16 if channel not in WirelessChannelChoices.values(): 

17 raise ValueError(_("Invalid channel value: {channel}").format(channel=channel)) 

18 

19 channel_values = channel.split('-') 

20 attrs = { 

21 'band': channel_values[0], 

22 'id': int(channel_values[1]), 

23 'frequency': Decimal(channel_values[2]), 

24 'width': Decimal(channel_values[3]), 

25 } 

26 if attr not in attrs: 

27 raise ValueError(_("Invalid channel attribute: {name}").format(name=attr)) 

28 

29 return attrs[attr]