Skip to content

Commit

Permalink
[OpenWrt] Ignore advanced wifi options if zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Mar 21, 2016
1 parent c8c95d6 commit a226e90
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
7 changes: 5 additions & 2 deletions netjsonconfig/backends/openwrt/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ def _get_wifi_interfaces(self):
'frag_threshold': 'frag'
}
for netjson_key, uci_key in wifi_options.items():
if wireless.get(netjson_key) is not None:
uci_wifi[uci_key] = wireless[netjson_key]
value = wireless.get(netjson_key)
if value is not None:
# ignore if 0 (autogenerated UIs might use 0 as default value)
if value > 0:
uci_wifi[uci_key] = value
del uci_wifi[netjson_key]
# determine encryption for wifi
if uci_wifi.get('encryption'):
Expand Down
2 changes: 1 addition & 1 deletion netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"ack_distance": {
"type": "integer",
"title": "ACK distance",
"minimum": 1,
"minimum": 0,
"propertyOrder": 10,
},
"rts_threshold": {
Expand Down
40 changes: 40 additions & 0 deletions tests/openwrt/test_wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,5 +918,45 @@ def test_wds_ap(self):
option network 'wlan0'
option ssid 'MyWdsAp'
option wds '1'
""")
self.assertEqual(o.render(), expected)

def test_wifi_options_zero(self):
"""
ensure ack_distance, rts_threshold and frag_threshold
are ignored if left empty
"""
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "MyWifiAP",
"wmm": True,
"ack_distance": 0,
"rts_threshold": 0,
"frag_threshold": 0
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface
option device 'radio0'
option ifname 'wlan0'
option mode 'ap'
option network 'wlan0'
option ssid 'MyWifiAP'
option wmm '1'
""")
self.assertEqual(o.render(), expected)

0 comments on commit a226e90

Please sign in to comment.