1- """Adds config flow for Blueprint ."""
1+ """Adds config flow for PandaStatus ."""
22
33from __future__ import annotations
44
55import voluptuous as vol
66from homeassistant import config_entries
7- from homeassistant .const import CONF_PASSWORD , CONF_USERNAME
7+ from homeassistant .const import CONF_URL
88from homeassistant .helpers import selector
9- from homeassistant .helpers .aiohttp_client import async_create_clientsession
109from slugify import slugify
1110
12- from .api import (
13- IntegrationBlueprintApiClient ,
14- IntegrationBlueprintApiClientAuthenticationError ,
15- IntegrationBlueprintApiClientCommunicationError ,
16- IntegrationBlueprintApiClientError ,
17- )
1811from .const import DOMAIN , LOGGER
12+ from .websocket import (
13+ PandaStatusWebSocket ,
14+ PandaStatusWebsocketCommunicationError ,
15+ PandaStatusWebsocketError ,
16+ )
1917
2018
21- class BlueprintFlowHandler (config_entries .ConfigFlow , domain = DOMAIN ):
22- """Config flow for Blueprint ."""
19+ class PandaStatusFlowHandler (config_entries .ConfigFlow , domain = DOMAIN ):
20+ """Config flow for PandaStatus ."""
2321
2422 VERSION = 1
2523
@@ -32,58 +30,40 @@ async def async_step_user(
3230 if user_input is not None :
3331 try :
3432 await self ._test_credentials (
35- username = user_input [CONF_USERNAME ],
36- password = user_input [CONF_PASSWORD ],
33+ url = user_input [CONF_URL ],
3734 )
38- except IntegrationBlueprintApiClientAuthenticationError as exception :
39- LOGGER .warning (exception )
40- _errors ["base" ] = "auth"
41- except IntegrationBlueprintApiClientCommunicationError as exception :
35+ except PandaStatusWebsocketCommunicationError as exception :
4236 LOGGER .error (exception )
4337 _errors ["base" ] = "connection"
44- except IntegrationBlueprintApiClientError as exception :
38+ except PandaStatusWebsocketError as exception :
4539 LOGGER .exception (exception )
4640 _errors ["base" ] = "unknown"
4741 else :
48- await self .async_set_unique_id (
49- ## Do NOT use this in production code
50- ## The unique_id should never be something that can change
51- ## https://developers.home-assistant.io/docs/config_entries_config_flow_handler#unique-ids
52- unique_id = slugify (user_input [CONF_USERNAME ])
53- )
42+ await self .async_set_unique_id (unique_id = slugify (user_input [CONF_URL ]))
5443 self ._abort_if_unique_id_configured ()
44+
5545 return self .async_create_entry (
56- title = user_input [CONF_USERNAME ],
57- data = user_input ,
46+ title = user_input [CONF_URL ], data = user_input
5847 )
5948
6049 return self .async_show_form (
6150 step_id = "user" ,
6251 data_schema = vol .Schema (
6352 {
6453 vol .Required (
65- CONF_USERNAME ,
66- default = (user_input or {}).get (CONF_USERNAME , vol .UNDEFINED ),
54+ CONF_URL ,
55+ default = (user_input or {}).get (CONF_URL , vol .UNDEFINED ),
6756 ): selector .TextSelector (
6857 selector .TextSelectorConfig (
6958 type = selector .TextSelectorType .TEXT ,
7059 ),
7160 ),
72- vol .Required (CONF_PASSWORD ): selector .TextSelector (
73- selector .TextSelectorConfig (
74- type = selector .TextSelectorType .PASSWORD ,
75- ),
76- ),
7761 },
7862 ),
7963 errors = _errors ,
8064 )
8165
82- async def _test_credentials (self , username : str , password : str ) -> None :
66+ async def _test_credentials (self , url : str ) -> None :
8367 """Validate credentials."""
84- client = IntegrationBlueprintApiClient (
85- username = username ,
86- password = password ,
87- session = async_create_clientsession (self .hass ),
88- )
68+ client = PandaStatusWebSocket (url = url , session = None )
8969 await client .async_get_data ()
0 commit comments