Add application credentials platform (#69148)
* Initial developer credentials scaffolding - Support websocket list/add/delete - Add developer credentials protocol from yaml config - Handle OAuth credential registration and de-registration - Tests for websocket and integration based registration * Fix pydoc text * Remove translations and update owners * Update homeassistant/components/developer_credentials/__init__.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/developer_credentials/__init__.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Remove _async_get_developer_credential * Rename to application credentials platform * Fix race condition and add import support * Increase code coverage (92%) * Increase test coverage 93% * Increase test coverage (94%) * Increase test coverage (97%) * Increase test covearge (98%) * Increase test coverage (99%) * Increase test coverage (100%) * Remove http router frozen comment * Remove auth domain override on import * Remove debug statement * Don't import the same client id multiple times * Add auth dependency for local oauth implementation * Revert older oauth2 changes from merge * Update homeassistant/components/application_credentials/__init__.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Move config credential import to its own fixture * Override the mock_application_credentials_integration fixture instead per test * Update application credentials * Add dictionary typing * Use f-strings as per feedback * Add additional structure needed for an MVP application credential Add additional structure needed for an MVP, including a target component Xbox * Add websocket to list supported integrations for frontend selector * Application credentials config * Import xbox credentials * Remove unnecessary async calls * Update script/hassfest/application_credentials.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update script/hassfest/application_credentials.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update script/hassfest/application_credentials.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update script/hassfest/application_credentials.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Import credentials with a fixed auth domain Resolve an issue with compatibility of exisiting config entries when importing client credentials Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
ae8604d429
commit
00b5d30e24
17 changed files with 1006 additions and 25 deletions
63
script/hassfest/application_credentials.py
Normal file
63
script/hassfest/application_credentials.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
"""Generate application_credentials data."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .model import Config, Integration
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
|
||||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
|
||||
# fmt: off
|
||||
|
||||
APPLICATION_CREDENTIALS = {}
|
||||
""".strip()
|
||||
|
||||
|
||||
def generate_and_validate(integrations: dict[str, Integration], config: Config) -> str:
|
||||
"""Validate and generate config flow data."""
|
||||
|
||||
match_list = []
|
||||
|
||||
for domain in sorted(integrations):
|
||||
integration = integrations[domain]
|
||||
application_credentials_file = integration.path / "application_credentials.py"
|
||||
if not application_credentials_file.is_file():
|
||||
continue
|
||||
|
||||
match_list.append(domain)
|
||||
|
||||
return BASE.format(json.dumps(match_list, indent=4))
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config) -> None:
|
||||
"""Validate application_credentials data."""
|
||||
application_credentials_path = (
|
||||
config.root / "homeassistant/generated/application_credentials.py"
|
||||
)
|
||||
config.cache["application_credentials"] = content = generate_and_validate(
|
||||
integrations, config
|
||||
)
|
||||
|
||||
if config.specific_integrations:
|
||||
return
|
||||
|
||||
if application_credentials_path.read_text(encoding="utf-8").strip() != content:
|
||||
config.add_error(
|
||||
"application_credentials",
|
||||
"File application_credentials.py is not up to date. Run python3 -m script.hassfest",
|
||||
fixable=True,
|
||||
)
|
||||
|
||||
|
||||
def generate(integrations: dict[str, Integration], config: Config):
|
||||
"""Generate application_credentials data."""
|
||||
application_credentials_path = (
|
||||
config.root / "homeassistant/generated/application_credentials.py"
|
||||
)
|
||||
application_credentials_path.write_text(
|
||||
f"{config.cache['application_credentials']}\n", encoding="utf-8"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue