diff --git a/.coveragerc b/.coveragerc index f3dd3d9115ef9d5d390f7392cf8624be66661c95..2b522f42893e2b7be5fa312a82138fa588a573eb 100644 --- a/.coveragerc +++ b/.coveragerc @@ -65,6 +65,8 @@ omit = homeassistant/components/scsgate.py homeassistant/components/*/scsgate.py + homeassistant/components/zeroconf.py + homeassistant/components/binary_sensor/arest.py homeassistant/components/binary_sensor/rest.py homeassistant/components/browser.py diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index f03fdf35929dd7b25965e8d2b9c7e375dceba207..900d826e61a643bfeaf8bc7ade0ce0f5da7dcccf 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -15,7 +15,7 @@ from homeassistant.const import ( EVENT_PLATFORM_DISCOVERED) DOMAIN = "discovery" -REQUIREMENTS = ['netdisco==0.6.2'] +REQUIREMENTS = ['netdisco==0.6.4'] SCAN_INTERVAL = 300 # seconds diff --git a/homeassistant/components/zeroconf.py b/homeassistant/components/zeroconf.py new file mode 100644 index 0000000000000000000000000000000000000000..bda6dcb153ba8e3086841b0ebf58aaaeafba67d6 --- /dev/null +++ b/homeassistant/components/zeroconf.py @@ -0,0 +1,50 @@ +""" +This module exposes Home Assistant via Zeroconf. + +Zeroconf is also known as Bonjour, Avahi or Multicast DNS (mDNS). + +For more details about Zeroconf, please refer to the documentation at +https://home-assistant.io/components/zeroconf/ +""" +import logging +import socket + +from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) + +REQUIREMENTS = ["zeroconf==0.17.5"] + +DEPENDENCIES = ["api"] + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = "zeroconf" + +ZEROCONF_TYPE = "_home-assistant._tcp.local." + + +def setup(hass, config): + """Set up Zeroconf and make Home Assistant discoverable.""" + from zeroconf import Zeroconf, ServiceInfo + + zeroconf = Zeroconf() + + zeroconf_name = "{}.{}".format(hass.config.location_name, + ZEROCONF_TYPE) + + params = {"version": __version__, "base_url": hass.config.api.base_url, + "needs_auth": (hass.config.api.api_password is not None)} + + info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, + socket.inet_aton(hass.config.api.host), + hass.config.api.port, 0, 0, params) + + zeroconf.register_service(info) + + def stop_zeroconf(event): + """Stop Zeroconf.""" + zeroconf.unregister_service(info) + zeroconf.close() + + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf) + + return True diff --git a/requirements_all.txt b/requirements_all.txt index eaf37715e456047cf755cf9482a98ce5bb3d3e63..6b34aad3be1b58c6a60bcaf18508d0b00d2139af 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -136,7 +136,7 @@ messagebird==1.1.1 mficlient==0.3.0 # homeassistant.components.discovery -netdisco==0.6.2 +netdisco==0.6.4 # homeassistant.components.sensor.neurio_energy neurio==0.2.10 @@ -317,3 +317,6 @@ xbee-helper==0.0.6 # homeassistant.components.sensor.yr xmltodict + +# homeassistant.components.zeroconf +zeroconf==0.17.5