Fix multi wifi validation

This commit is contained in:
Otto Winter 2018-06-11 16:13:46 +02:00
parent e0acdc3ae0
commit 2c30d80490
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E

View file

@ -55,13 +55,12 @@ WIFI_NETWORK_STA = WIFI_NETWORK_BASE.extend({
}) })
def validate_multi_wifi(config): def validate(config):
if CONF_PASSWORD in config and CONF_SSID not in config: if CONF_PASSWORD in config and CONF_SSID not in config:
raise vol.Invalid("Cannot have WiFi password without SSID!") raise vol.Invalid("Cannot have WiFi password without SSID!")
if CONF_SSID in config and CONF_NETWORKS in config: if CONF_SSID not in config and CONF_AP not in config:
raise vol.Invalid("For multi-wifi mode (with 'networks:'), please specify all " raise vol.Invalid("Please specify at least an SSID or an Access Point "
"networks within the 'networks:' key!") "to create.")
return config return config
@ -79,7 +78,7 @@ CONFIG_SCHEMA = vol.All(vol.Schema({
vol.Optional(CONF_AP): WIFI_NETWORK_AP, vol.Optional(CONF_AP): WIFI_NETWORK_AP,
vol.Optional(CONF_HOSTNAME): cv.hostname, vol.Optional(CONF_HOSTNAME): cv.hostname,
vol.Optional(CONF_DOMAIN, default='.local'): cv.domainname, vol.Optional(CONF_DOMAIN, default='.local'): cv.domainname,
}), validate_multi_wifi) }), validate)
def safe_ip(ip): def safe_ip(ip):
@ -112,14 +111,11 @@ def wifi_network(config):
def to_code(config): def to_code(config):
if CONF_SSID in config: rhs = App.init_wifi()
rhs = App.init_wifi(config[CONF_SSID], config.get(CONF_PASSWORD))
else:
rhs = App.init_wifi()
wifi = Pvariable(config[CONF_ID], rhs) wifi = Pvariable(config[CONF_ID], rhs)
if CONF_MANUAL_IP in config: if CONF_SSID in config:
add(wifi.set_sta_manual_ip(manual_ip(config[CONF_MANUAL_IP]))) add(wifi.set_sta(wifi_network(config)))
if CONF_AP in config: if CONF_AP in config:
add(wifi.set_ap(wifi_network(config[CONF_AP]))) add(wifi.set_ap(wifi_network(config[CONF_AP])))