Remove deprecated CONF_ALLOW_UNLOCK, CONF_API_KEY from Google Assistant (#44087)
* Remove deprecated CONF_ALLOW_UNLOCK, CONF_API_KEY * Use vol.Remove() to prevent setup fail * Keep constants
This commit is contained in:
parent
97edbaa85f
commit
9cc406fef9
3 changed files with 8 additions and 34 deletions
|
@ -11,8 +11,6 @@ from homeassistant.helpers import config_validation as cv
|
|||
|
||||
from .const import (
|
||||
CONF_ALIASES,
|
||||
CONF_ALLOW_UNLOCK,
|
||||
CONF_API_KEY,
|
||||
CONF_CLIENT_EMAIL,
|
||||
CONF_ENTITY_CONFIG,
|
||||
CONF_EXPOSE,
|
||||
|
@ -36,6 +34,9 @@ from .const import EVENT_COMMAND_RECEIVED, EVENT_SYNC_RECEIVED # noqa: F401, is
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ALLOW_UNLOCK = "allow_unlock"
|
||||
CONF_API_KEY = "api_key"
|
||||
|
||||
ENTITY_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
|
@ -61,8 +62,6 @@ def _check_report_state(data):
|
|||
|
||||
|
||||
GOOGLE_ASSISTANT_SCHEMA = vol.All(
|
||||
cv.deprecated(CONF_ALLOW_UNLOCK, invalidation_version="0.95"),
|
||||
cv.deprecated(CONF_API_KEY, invalidation_version="0.105"),
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_PROJECT_ID): cv.string,
|
||||
|
@ -72,13 +71,14 @@ GOOGLE_ASSISTANT_SCHEMA = vol.All(
|
|||
vol.Optional(
|
||||
CONF_EXPOSED_DOMAINS, default=DEFAULT_EXPOSED_DOMAINS
|
||||
): cv.ensure_list,
|
||||
vol.Optional(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_ENTITY_CONFIG): {cv.entity_id: ENTITY_SCHEMA},
|
||||
vol.Optional(CONF_ALLOW_UNLOCK): cv.boolean,
|
||||
# str on purpose, makes sure it is configured correctly.
|
||||
vol.Optional(CONF_SECURE_DEVICES_PIN): str,
|
||||
vol.Optional(CONF_REPORT_STATE, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SERVICE_ACCOUNT): GOOGLE_SERVICE_ACCOUNT,
|
||||
# deprecated configuration options
|
||||
vol.Remove(CONF_ALLOW_UNLOCK): cv.boolean,
|
||||
vol.Remove(CONF_API_KEY): cv.string,
|
||||
},
|
||||
extra=vol.PREVENT_EXTRA,
|
||||
),
|
||||
|
@ -113,7 +113,7 @@ async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
|
|||
await google_config.async_sync_entities(agent_user_id)
|
||||
|
||||
# Register service only if key is provided
|
||||
if CONF_API_KEY in config or CONF_SERVICE_ACCOUNT in config:
|
||||
if CONF_SERVICE_ACCOUNT in config:
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_REQUEST_SYNC, request_sync_service_handler
|
||||
)
|
||||
|
|
|
@ -30,9 +30,7 @@ CONF_EXPOSE_BY_DEFAULT = "expose_by_default"
|
|||
CONF_EXPOSED_DOMAINS = "exposed_domains"
|
||||
CONF_PROJECT_ID = "project_id"
|
||||
CONF_ALIASES = "aliases"
|
||||
CONF_API_KEY = "api_key"
|
||||
CONF_ROOM_HINT = "room"
|
||||
CONF_ALLOW_UNLOCK = "allow_unlock"
|
||||
CONF_SECURE_DEVICES_PIN = "secure_devices_pin"
|
||||
CONF_REPORT_STATE = "report_state"
|
||||
CONF_SERVICE_ACCOUNT = "service_account"
|
||||
|
|
|
@ -19,7 +19,6 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
CONF_API_KEY,
|
||||
CONF_CLIENT_EMAIL,
|
||||
CONF_ENTITY_CONFIG,
|
||||
CONF_EXPOSE,
|
||||
|
@ -135,11 +134,7 @@ class GoogleConfig(AbstractConfig):
|
|||
return True
|
||||
|
||||
async def _async_request_sync_devices(self, agent_user_id: str):
|
||||
if CONF_API_KEY in self._config:
|
||||
await self.async_call_homegraph_api_key(
|
||||
REQUEST_SYNC_BASE_URL, {"agentUserId": agent_user_id}
|
||||
)
|
||||
elif CONF_SERVICE_ACCOUNT in self._config:
|
||||
if CONF_SERVICE_ACCOUNT in self._config:
|
||||
await self.async_call_homegraph_api(
|
||||
REQUEST_SYNC_BASE_URL, {"agentUserId": agent_user_id}
|
||||
)
|
||||
|
@ -164,25 +159,6 @@ class GoogleConfig(AbstractConfig):
|
|||
self._access_token = token["access_token"]
|
||||
self._access_token_renew = now + timedelta(seconds=token["expires_in"])
|
||||
|
||||
async def async_call_homegraph_api_key(self, url, data):
|
||||
"""Call a homegraph api with api key authentication."""
|
||||
websession = async_get_clientsession(self.hass)
|
||||
try:
|
||||
res = await websession.post(
|
||||
url, params={"key": self._config.get(CONF_API_KEY)}, json=data
|
||||
)
|
||||
_LOGGER.debug(
|
||||
"Response on %s with data %s was %s", url, data, await res.text()
|
||||
)
|
||||
res.raise_for_status()
|
||||
return res.status
|
||||
except ClientResponseError as error:
|
||||
_LOGGER.error("Request for %s failed: %d", url, error.status)
|
||||
return error.status
|
||||
except (asyncio.TimeoutError, ClientError):
|
||||
_LOGGER.error("Could not contact %s", url)
|
||||
return HTTP_INTERNAL_SERVER_ERROR
|
||||
|
||||
async def async_call_homegraph_api(self, url, data):
|
||||
"""Call a homegraph api with authentication."""
|
||||
session = async_get_clientsession(self.hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue