Final clean up, flake8, pylint, change a variable name, remove unnecessary imports

This commit is contained in:
Robbie Trencheny committed 2016-04-10 16:02:07 -07:00
1 parent c33c2c01d2
commit beac69ad17
2 files changed
+28 -26

No files matched your search

+22 -23
View File
@@ -1,6 +1,7 @@
"""
This module exposes Home Assistant via Zeroconf, also sometimes known as
Bonjour, Rendezvous, Avahi or Multicast DNS (mDNS).
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/
@@ -8,10 +9,7 @@ https://home-assistant.io/components/zeroconf/
import logging
import socket
from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, __version__)
import homeassistant.util as util
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
REQUIREMENTS = ["zeroconf==0.17.5"]
@@ -21,30 +19,31 @@ DOMAIN = "zeroconf"
ZEROCONF_TYPE = "_home-assistant._tcp.local."
DEPENDENCIES = ["http", "api"]
DEPENDENCIES = ["http"]
def setup(hass, config):
"""Set up Zeroconf and make Home Assistant discoverable."""
from zeroconf import Zeroconf, ServiceInfo
from zeroconf import Zeroconf, ServiceInfo
zeroconf = Zeroconf()
zeroconf = Zeroconf()
zeroconf_name = "{}.{}".format(hass.config.location_name,
ZEROCONF_TYPE)
zeroconf_name = "{}.{}".format(hass.config.location_name,
ZEROCONF_TYPE)
params = {"version": __version__, "base_url": hass.http.base_url,
"needs_auth": (hass.http.api_password != "")}
params = {"version": __version__, "base_url": hass.http.base_url,
"has_password": (hass.http.api_password != "")}
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
socket.inet_aton(hass.http.routable_address),
hass.http.server_address[1], 0, 0, params)
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
socket.inet_aton(util.get_local_ip()),
hass.http.server_address[1], 0, 0, params)
zeroconf.register_service(info)
zeroconf.register_service(info)
def stop_zeroconf(event):
"""Stop Zeroconf."""
zeroconf.unregister_service(info)
def stop_zeroconf(event):
"""Stop Zeroconf."""
zeroconf.unregister_all_services()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
return True
return True