Remove zeroconf options from homekit (#35687)

* Remove zeroconf options from homekit

homekit uses the system shared zeroconf instance which
made the interface choice option controlled by the
zeroconf integration setting.

* change to cv.deprecated

* adj

* fix remaining tests from original merge conflict

* remove invalidation_version
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-06-02 17:47:39 -05:00
1 parent bfc5aa90b1
commit 5f4fdaa171
7 files changed
+48 -149

No files matched your search

+22 -37
View File
@@ -6,7 +6,6 @@ import os
from aiohttp import web
import voluptuous as vol
from zeroconf import InterfaceChoice
from homeassistant.components import zeroconf
from homeassistant.components.binary_sensor import (
@@ -71,7 +70,6 @@ from .const import (
DEFAULT_AUTO_START,
DEFAULT_PORT,
DEFAULT_SAFE_MODE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
DOMAIN,
EVENT_HOMEKIT_CHANGED,
HOMEKIT,
@@ -113,23 +111,24 @@ def _has_all_unique_names_and_ports(bridges):
return bridges
BRIDGE_SCHEMA = vol.Schema(
{
vol.Optional(CONF_NAME, default=BRIDGE_NAME): vol.All(
cv.string, vol.Length(min=3, max=25)
),
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_IP_ADDRESS): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_ADVERTISE_IP): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): cv.boolean,
vol.Optional(CONF_SAFE_MODE, default=DEFAULT_SAFE_MODE): cv.boolean,
vol.Optional(CONF_FILTER, default={}): BASE_FILTER_SCHEMA,
vol.Optional(CONF_ENTITY_CONFIG, default={}): validate_entity_config,
vol.Optional(
CONF_ZEROCONF_DEFAULT_INTERFACE, default=DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
): cv.boolean,
},
extra=vol.ALLOW_EXTRA,
BRIDGE_SCHEMA = vol.All(
cv.deprecated(CONF_ZEROCONF_DEFAULT_INTERFACE),
vol.Schema(
{
vol.Optional(CONF_NAME, default=BRIDGE_NAME): vol.All(
cv.string, vol.Length(min=3, max=25)
),
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_IP_ADDRESS): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_ADVERTISE_IP): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): cv.boolean,
vol.Optional(CONF_SAFE_MODE, default=DEFAULT_SAFE_MODE): cv.boolean,
vol.Optional(CONF_FILTER, default={}): BASE_FILTER_SCHEMA,
vol.Optional(CONF_ENTITY_CONFIG, default={}): validate_entity_config,
vol.Optional(CONF_ZEROCONF_DEFAULT_INTERFACE): cv.boolean,
},
extra=vol.ALLOW_EXTRA,
),
)
CONFIG_SCHEMA = vol.Schema(
@@ -233,11 +232,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
},
)
)
interface_choice = (
InterfaceChoice.Default
if options.get(CONF_ZEROCONF_DEFAULT_INTERFACE)
else None
)
homekit = HomeKit(
hass,
@@ -248,11 +242,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
entity_config,
safe_mode,
advertise_ip,
interface_choice,
entry.entry_id,
)
await hass.async_add_executor_job(homekit.setup)
await homekit.async_setup_zeroconf()
zeroconf_instance = await zeroconf.async_get_instance(hass)
await hass.async_add_executor_job(homekit.setup, zeroconf_instance)
undo_listener = entry.add_update_listener(_async_update_listener)
@@ -404,7 +397,6 @@ class HomeKit:
entity_config,
safe_mode,
advertise_ip=None,
interface_choice=None,
entry_id=None,
):
"""Initialize a HomeKit object."""
@@ -416,14 +408,13 @@ class HomeKit:
self._config = entity_config
self._safe_mode = safe_mode
self._advertise_ip = advertise_ip
self._interface_choice = interface_choice
self._entry_id = entry_id
self.status = STATUS_READY
self.bridge = None
self.driver = None
def setup(self):
def setup(self, zeroconf_instance):
"""Set up bridge and accessory driver."""
# pylint: disable=import-outside-toplevel
from .accessories import HomeBridge, HomeDriver
@@ -440,7 +431,7 @@ class HomeKit:
port=self._port,
persist_file=persist_file,
advertised_address=self._advertise_ip,
interface_choice=self._interface_choice,
zeroconf_instance=zeroconf_instance,
)
# If we do not load the mac address will be wrong
@@ -455,12 +446,6 @@ class HomeKit:
_LOGGER.debug("Safe_mode selected for %s", self._name)
self.driver.safe_mode = True
async def async_setup_zeroconf(self):
"""Share the system zeroconf instance."""
# Replace the existing zeroconf instance.
await self.hass.async_add_executor_job(self.driver.advertiser.close)
self.driver.advertiser = await zeroconf.async_get_instance(self.hass)
def reset_accessories(self, entity_ids):
"""Reset the accessory to load the latest configuration."""
aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE]
@@ -23,11 +23,9 @@ from .const import (
CONF_FILTER,
CONF_SAFE_MODE,
CONF_VIDEO_CODEC,
CONF_ZEROCONF_DEFAULT_INTERFACE,
DEFAULT_AUTO_START,
DEFAULT_CONFIG_FLOW_PORT,
DEFAULT_SAFE_MODE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
SHORT_BRIDGE_NAME,
VIDEO_CODEC_COPY,
)
@@ -227,14 +225,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
vol.Optional(
CONF_SAFE_MODE,
default=self.homekit_options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE),
): bool,
vol.Optional(
CONF_ZEROCONF_DEFAULT_INTERFACE,
default=self.homekit_options.get(
CONF_ZEROCONF_DEFAULT_INTERFACE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
),
): bool,
): bool
}
)
@@ -68,7 +68,6 @@ DEFAULT_MAX_WIDTH = 1920
DEFAULT_PORT = 51827
DEFAULT_CONFIG_FLOW_PORT = 51828
DEFAULT_SAFE_MODE = False
DEFAULT_ZEROCONF_DEFAULT_INTERFACE = False
DEFAULT_VIDEO_CODEC = VIDEO_CODEC_LIBX264
DEFAULT_VIDEO_MAP = "0:v:0"
DEFAULT_VIDEO_PACKET_SIZE = 1316
@@ -267,7 +266,6 @@ HK_NOT_CHARGABLE = 2
CONFIG_OPTIONS = [
CONF_FILTER,
CONF_AUTO_START,
CONF_ZEROCONF_DEFAULT_INTERFACE,
CONF_SAFE_MODE,
CONF_ENTITY_CONFIG,
]
@@ -30,8 +30,7 @@
"advanced": {
"data": {
"auto_start": "[%key:component::homekit::config::step::user::data::auto_start%]",
"safe_mode": "Safe Mode (enable only if pairing fails)",
"zeroconf_default_interface": "Use default zeroconf interface (enable if the bridge cannot be found in the Home app)"
"safe_mode": "Safe Mode (enable only if pairing fails)"
},
"description": "These settings only need to be adjusted if the HomeKit bridge is not functional.",
"title": "Advanced Configuration"
@@ -23,8 +23,7 @@
"advanced": {
"data": {
"auto_start": "Autostart (disable if using Z-Wave or other delayed start system)",
"safe_mode": "Safe Mode (enable only if pairing fails)",
"zeroconf_default_interface": "Use default zeroconf interface (enable if the bridge cannot be found in the Home app)"
"safe_mode": "Safe Mode (enable only if pairing fails)"
},
"description": "These settings only need to be adjusted if the HomeKit bridge is not functional.",
"title": "Advanced Configuration"