Don't initialize components which have already been discovered (#6381)

* Don't initialize components which have already been discovered (fixes #5588)

* Don't log that we've found a service unless we know it's not a duplicate

* Encode discovery data hash with JSON

This also solves the issue of trying to hash non-hashable objects like dicts

* Add test for duplicate device discovery
This commit is contained in:
Colin O'Dell authored and Paulus Schoutsen committed 2017-03-03 13:11:40 -08:00
1 parent 35fcc299c0
commit 0489ae53c4
2 files changed
+37 -2

No files matched your search

+10 -2
View File
@@ -7,6 +7,7 @@ Knows which components handle certain types, will make sure they are
loaded before the EVENT_PLATFORM_DISCOVERED is fired.
"""
import asyncio
import json
from datetime import timedelta
import logging
@@ -66,6 +67,7 @@ def async_setup(hass, config):
logger = logging.getLogger(__name__)
netdisco = NetworkDiscovery()
already_discovered = set()
# Disable zeroconf logging, it spams
logging.getLogger('zeroconf').setLevel(logging.CRITICAL)
@@ -80,14 +82,20 @@ def async_setup(hass, config):
logger.info("Ignoring service: %s %s", service, info)
return
logger.info("Found new service: %s %s", service, info)
comp_plat = SERVICE_HANDLERS.get(service)
# We do not know how to handle this service.
if not comp_plat:
return
discovery_hash = json.dumps([service, info], sort_keys=True)
if discovery_hash in already_discovered:
return
already_discovered.add(discovery_hash)
logger.info("Found new service: %s %s", service, info)
component, platform = comp_plat
if platform is None: