mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Final clean up, flake8, pylint, change a variable name, remove unnecessary imports
This commit is contained in:
parent
c33c2c01d2
commit
beac69ad17
@ -7,7 +7,6 @@ https://home-assistant.io/developers/api/
|
|||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
import ssl
|
import ssl
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@ -28,7 +27,7 @@ from homeassistant.const import (
|
|||||||
HTTP_HEADER_CONTENT_LENGTH, HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_EXPIRES,
|
HTTP_HEADER_CONTENT_LENGTH, HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_EXPIRES,
|
||||||
HTTP_HEADER_HA_AUTH, HTTP_HEADER_VARY, HTTP_METHOD_NOT_ALLOWED,
|
HTTP_HEADER_HA_AUTH, HTTP_HEADER_VARY, HTTP_METHOD_NOT_ALLOWED,
|
||||||
HTTP_NOT_FOUND, HTTP_OK, HTTP_UNAUTHORIZED, HTTP_UNPROCESSABLE_ENTITY,
|
HTTP_NOT_FOUND, HTTP_OK, HTTP_UNAUTHORIZED, HTTP_UNPROCESSABLE_ENTITY,
|
||||||
SERVER_PORT, __version__)
|
SERVER_PORT)
|
||||||
|
|
||||||
DOMAIN = "http"
|
DOMAIN = "http"
|
||||||
|
|
||||||
@ -105,8 +104,12 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
|
|||||||
self.paths = []
|
self.paths = []
|
||||||
self.sessions = SessionStore()
|
self.sessions = SessionStore()
|
||||||
self.protocol = 'https' if ssl_certificate is not None else 'http'
|
self.protocol = 'https' if ssl_certificate is not None else 'http'
|
||||||
|
if server_address[0] == '0.0.0.0':
|
||||||
|
self.routable_address = util.get_local_ip()
|
||||||
|
else:
|
||||||
|
self.routable_address = server_address[0]
|
||||||
self.base_url = "{}://{}:{}".format(self.protocol,
|
self.base_url = "{}://{}:{}".format(self.protocol,
|
||||||
util.get_local_ip(),
|
self.routable_address,
|
||||||
self.server_address[1])
|
self.server_address[1])
|
||||||
|
|
||||||
# We will lazy init this one if needed
|
# We will lazy init this one if needed
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
This module exposes Home Assistant via Zeroconf, also sometimes known as
|
This module exposes Home Assistant via Zeroconf.
|
||||||
Bonjour, Rendezvous, Avahi or Multicast DNS (mDNS).
|
|
||||||
|
Zeroconf is also known as Bonjour, Avahi or Multicast DNS (mDNS).
|
||||||
|
|
||||||
For more details about Zeroconf, please refer to the documentation at
|
For more details about Zeroconf, please refer to the documentation at
|
||||||
https://home-assistant.io/components/zeroconf/
|
https://home-assistant.io/components/zeroconf/
|
||||||
@ -8,10 +9,7 @@ https://home-assistant.io/components/zeroconf/
|
|||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
|
||||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, __version__)
|
|
||||||
|
|
||||||
import homeassistant.util as util
|
|
||||||
|
|
||||||
REQUIREMENTS = ["zeroconf==0.17.5"]
|
REQUIREMENTS = ["zeroconf==0.17.5"]
|
||||||
|
|
||||||
@ -21,10 +19,11 @@ DOMAIN = "zeroconf"
|
|||||||
|
|
||||||
ZEROCONF_TYPE = "_home-assistant._tcp.local."
|
ZEROCONF_TYPE = "_home-assistant._tcp.local."
|
||||||
|
|
||||||
DEPENDENCIES = ["http", "api"]
|
DEPENDENCIES = ["http"]
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
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()
|
||||||
@ -33,17 +32,17 @@ def setup(hass, config):
|
|||||||
ZEROCONF_TYPE)
|
ZEROCONF_TYPE)
|
||||||
|
|
||||||
params = {"version": __version__, "base_url": hass.http.base_url,
|
params = {"version": __version__, "base_url": hass.http.base_url,
|
||||||
"has_password": (hass.http.api_password != "")}
|
"needs_auth": (hass.http.api_password != "")}
|
||||||
|
|
||||||
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
|
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
|
||||||
socket.inet_aton(util.get_local_ip()),
|
socket.inet_aton(hass.http.routable_address),
|
||||||
hass.http.server_address[1], 0, 0, params)
|
hass.http.server_address[1], 0, 0, params)
|
||||||
|
|
||||||
zeroconf.register_service(info)
|
zeroconf.register_service(info)
|
||||||
|
|
||||||
def stop_zeroconf(event):
|
def stop_zeroconf(event):
|
||||||
"""Stop Zeroconf."""
|
"""Stop Zeroconf."""
|
||||||
zeroconf.unregister_all_services()
|
zeroconf.unregister_service(info)
|
||||||
|
|
||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user