mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Fix oauth debug log bug in Teslemetry (#161652)
This commit is contained in:
@@ -102,7 +102,11 @@ async def _get_access_token(oauth_session: OAuth2Session) -> str:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -> bool:
|
||||
"""Set up Teslemetry config."""
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
if "token" not in entry.data:
|
||||
raise ConfigEntryAuthFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="token_data_malformed",
|
||||
)
|
||||
|
||||
try:
|
||||
implementation = await async_get_config_entry_implementation(hass, entry)
|
||||
@@ -113,6 +117,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
||||
) from err
|
||||
oauth_session = OAuth2Session(hass, entry, implementation)
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
|
||||
# Create API connection
|
||||
access_token = partial(_get_access_token, oauth_session)
|
||||
teslemetry = Teslemetry(
|
||||
|
||||
@@ -649,6 +649,26 @@ async def test_live_status_generic_error(
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_missing_token_data(hass: HomeAssistant) -> None:
|
||||
"""Test that missing token data in config entry triggers auth failure."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
version=2,
|
||||
unique_id=UNIQUE_ID,
|
||||
data={
|
||||
"auth_implementation": DOMAIN,
|
||||
# token is intentionally missing
|
||||
},
|
||||
)
|
||||
mock_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry = hass.config_entries.async_get_entry(mock_entry.entry_id)
|
||||
assert entry is not None
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_vehicle_streaming_version_update(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
|
||||
Reference in New Issue
Block a user