mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Support setting manual_ip under networks option (#2839)
This commit is contained in:
		| @@ -221,10 +221,22 @@ def _validate(config): | |||||||
|             raise cv.Invalid("Fast connect can only be used with one network!") |             raise cv.Invalid("Fast connect can only be used with one network!") | ||||||
|  |  | ||||||
|     if CONF_USE_ADDRESS not in config: |     if CONF_USE_ADDRESS not in config: | ||||||
|  |         use_address = CORE.name + config[CONF_DOMAIN] | ||||||
|         if CONF_MANUAL_IP in config: |         if CONF_MANUAL_IP in config: | ||||||
|             use_address = str(config[CONF_MANUAL_IP][CONF_STATIC_IP]) |             use_address = str(config[CONF_MANUAL_IP][CONF_STATIC_IP]) | ||||||
|         else: |         elif CONF_NETWORKS in config: | ||||||
|             use_address = CORE.name + config[CONF_DOMAIN] |             ips = set( | ||||||
|  |                 str(net[CONF_MANUAL_IP][CONF_STATIC_IP]) | ||||||
|  |                 for net in config[CONF_NETWORKS] | ||||||
|  |                 if CONF_MANUAL_IP in net | ||||||
|  |             ) | ||||||
|  |             if len(ips) > 1: | ||||||
|  |                 raise cv.Invalid( | ||||||
|  |                     "Must specify use_address when using multiple static IP addresses." | ||||||
|  |                 ) | ||||||
|  |             if len(ips) == 1: | ||||||
|  |                 use_address = next(iter(ips)) | ||||||
|  |  | ||||||
|         config[CONF_USE_ADDRESS] = use_address |         config[CONF_USE_ADDRESS] = use_address | ||||||
|  |  | ||||||
|     return config |     return config | ||||||
| @@ -334,7 +346,8 @@ async def to_code(config): | |||||||
|     cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) |     cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) | ||||||
|  |  | ||||||
|     for network in config.get(CONF_NETWORKS, []): |     for network in config.get(CONF_NETWORKS, []): | ||||||
|         cg.add(var.add_sta(wifi_network(network, config.get(CONF_MANUAL_IP)))) |         ip_config = network.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP)) | ||||||
|  |         cg.add(var.add_sta(wifi_network(network, ip_config))) | ||||||
|  |  | ||||||
|     if CONF_AP in config: |     if CONF_AP in config: | ||||||
|         conf = config[CONF_AP] |         conf = config[CONF_AP] | ||||||
|   | |||||||
| @@ -16,6 +16,10 @@ wifi: | |||||||
|   networks: |   networks: | ||||||
|     - ssid: 'MySSID' |     - ssid: 'MySSID' | ||||||
|       password: 'password1' |       password: 'password1' | ||||||
|  |       manual_ip: | ||||||
|  |         static_ip: 192.168.1.23 | ||||||
|  |         gateway: 192.168.1.1 | ||||||
|  |         subnet: 255.255.255.0 | ||||||
|  |  | ||||||
| api: | api: | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user