mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add DHCP discovery to Withings (#133737)
This commit is contained in:
parent
0037799bfe
commit
f2df57e230
@ -5,6 +5,11 @@
|
|||||||
"codeowners": ["@joostlek"],
|
"codeowners": ["@joostlek"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["application_credentials", "http", "webhook"],
|
"dependencies": ["application_credentials", "http", "webhook"],
|
||||||
|
"dhcp": [
|
||||||
|
{
|
||||||
|
"macaddress": "0024E4*"
|
||||||
|
}
|
||||||
|
],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/withings",
|
"documentation": "https://www.home-assistant.io/integrations/withings",
|
||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["aiowithings"],
|
"loggers": ["aiowithings"],
|
||||||
|
@ -1119,6 +1119,10 @@ DHCP: Final[list[dict[str, str | bool]]] = [
|
|||||||
"domain": "vicare",
|
"domain": "vicare",
|
||||||
"macaddress": "B87424*",
|
"macaddress": "B87424*",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"domain": "withings",
|
||||||
|
"macaddress": "0024E4*",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"domain": "wiz",
|
"domain": "wiz",
|
||||||
"registered_devices": True,
|
"registered_devices": True,
|
||||||
|
@ -4,8 +4,9 @@ from unittest.mock import AsyncMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.dhcp import DhcpServiceInfo
|
||||||
from homeassistant.components.withings.const import DOMAIN
|
from homeassistant.components.withings.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
@ -293,3 +294,65 @@ async def test_config_flow_with_invalid_credentials(
|
|||||||
assert result
|
assert result
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "oauth_error"
|
assert result["reason"] == "oauth_error"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("current_request_with_host")
|
||||||
|
async def test_dhcp(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
) -> None:
|
||||||
|
"""Check DHCP discovery."""
|
||||||
|
|
||||||
|
service_info = DhcpServiceInfo(
|
||||||
|
hostname="device",
|
||||||
|
ip="192.168.0.1",
|
||||||
|
macaddress="0024e4bd30de",
|
||||||
|
)
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_DHCP}, data=service_info
|
||||||
|
)
|
||||||
|
state = config_entry_oauth2_flow._encode_jwt(
|
||||||
|
hass,
|
||||||
|
{
|
||||||
|
"flow_id": result["flow_id"],
|
||||||
|
"redirect_uri": "https://example.com/auth/external/callback",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.EXTERNAL_STEP
|
||||||
|
assert result["url"] == (
|
||||||
|
"https://account.withings.com/oauth2_user/authorize2?"
|
||||||
|
f"response_type=code&client_id={CLIENT_ID}&"
|
||||||
|
"redirect_uri=https://example.com/auth/external/callback&"
|
||||||
|
f"state={state}"
|
||||||
|
"&scope=user.info,user.metrics,user.activity,user.sleepevents"
|
||||||
|
)
|
||||||
|
|
||||||
|
client = await hass_client_no_auth()
|
||||||
|
resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
||||||
|
assert resp.status == 200
|
||||||
|
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
||||||
|
|
||||||
|
aioclient_mock.clear_requests()
|
||||||
|
aioclient_mock.post(
|
||||||
|
"https://wbsapi.withings.net/v2/oauth2",
|
||||||
|
json={
|
||||||
|
"body": {
|
||||||
|
"refresh_token": "mock-refresh-token",
|
||||||
|
"access_token": "mock-access-token",
|
||||||
|
"type": "Bearer",
|
||||||
|
"expires_in": 60,
|
||||||
|
"userid": 600,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.withings.async_setup_entry", return_value=True
|
||||||
|
) as mock_setup:
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user