Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -11,37 +11,35 @@ import voluptuous as vol
|
||||
from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf
|
||||
|
||||
from homeassistant import util
|
||||
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, __version__
|
||||
from homeassistant.generated.zeroconf import ZEROCONF, HOMEKIT
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'zeroconf'
|
||||
DOMAIN = "zeroconf"
|
||||
|
||||
ATTR_HOST = 'host'
|
||||
ATTR_PORT = 'port'
|
||||
ATTR_HOSTNAME = 'hostname'
|
||||
ATTR_TYPE = 'type'
|
||||
ATTR_NAME = 'name'
|
||||
ATTR_PROPERTIES = 'properties'
|
||||
ATTR_HOST = "host"
|
||||
ATTR_PORT = "port"
|
||||
ATTR_HOSTNAME = "hostname"
|
||||
ATTR_TYPE = "type"
|
||||
ATTR_NAME = "name"
|
||||
ATTR_PROPERTIES = "properties"
|
||||
|
||||
ZEROCONF_TYPE = '_home-assistant._tcp.local.'
|
||||
HOMEKIT_TYPE = '_hap._tcp.local.'
|
||||
ZEROCONF_TYPE = "_home-assistant._tcp.local."
|
||||
HOMEKIT_TYPE = "_hap._tcp.local."
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up Zeroconf and make Home Assistant discoverable."""
|
||||
zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
|
||||
zeroconf_name = "{}.{}".format(hass.config.location_name, ZEROCONF_TYPE)
|
||||
|
||||
params = {
|
||||
'version': __version__,
|
||||
'base_url': hass.config.api.base_url,
|
||||
"version": __version__,
|
||||
"base_url": hass.config.api.base_url,
|
||||
# always needs authentication
|
||||
'requires_api_password': True,
|
||||
"requires_api_password": True,
|
||||
}
|
||||
|
||||
host_ip = util.get_local_ip()
|
||||
@@ -51,9 +49,14 @@ def setup(hass, config):
|
||||
except socket.error:
|
||||
host_ip_pton = socket.inet_pton(socket.AF_INET6, host_ip)
|
||||
|
||||
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, None,
|
||||
addresses=[host_ip_pton], port=hass.http.server_port,
|
||||
properties=params)
|
||||
info = ServiceInfo(
|
||||
ZEROCONF_TYPE,
|
||||
zeroconf_name,
|
||||
None,
|
||||
addresses=[host_ip_pton],
|
||||
port=hass.http.server_port,
|
||||
properties=params,
|
||||
)
|
||||
|
||||
zeroconf = Zeroconf()
|
||||
|
||||
@@ -75,7 +78,7 @@ def setup(hass, config):
|
||||
for domain in ZEROCONF[service_type]:
|
||||
hass.add_job(
|
||||
hass.config_entries.flow.async_init(
|
||||
domain, context={'source': DOMAIN}, data=info
|
||||
domain, context={"source": DOMAIN}, data=info
|
||||
)
|
||||
)
|
||||
|
||||
@@ -101,10 +104,10 @@ def handle_homekit(hass, info) -> bool:
|
||||
Return if discovery was forwarded.
|
||||
"""
|
||||
model = None
|
||||
props = info.get('properties', {})
|
||||
props = info.get("properties", {})
|
||||
|
||||
for key in props:
|
||||
if key.lower() == 'md':
|
||||
if key.lower() == "md":
|
||||
model = props[key]
|
||||
break
|
||||
|
||||
@@ -117,7 +120,7 @@ def handle_homekit(hass, info) -> bool:
|
||||
|
||||
hass.add_job(
|
||||
hass.config_entries.flow.async_init(
|
||||
HOMEKIT[test_model], context={'source': 'homekit'}, data=info
|
||||
HOMEKIT[test_model], context={"source": "homekit"}, data=info
|
||||
)
|
||||
)
|
||||
return True
|
||||
@@ -132,8 +135,8 @@ def info_from_service(service):
|
||||
for key, value in service.properties.items():
|
||||
try:
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode('utf-8')
|
||||
properties[key.decode('utf-8')] = value
|
||||
value = value.decode("utf-8")
|
||||
properties[key.decode("utf-8")] = value
|
||||
except UnicodeDecodeError:
|
||||
_LOGGER.warning("Unicode decode error on %s: %s", key, value)
|
||||
|
||||
|
||||
Reference in new issue
Block a user