1414import voluptuous as vol
1515
1616from homeassistant .config_entries import ConfigFlow , ConfigFlowResult
17- from homeassistant .const import CONF_API_KEY , CONF_HOST , CONF_VERIFY_SSL
17+ from homeassistant .const import CONF_API_TOKEN , CONF_URL , CONF_VERIFY_SSL
1818from homeassistant .core import HomeAssistant
1919from homeassistant .exceptions import HomeAssistantError
2020from homeassistant .helpers .aiohttp_client import async_get_clientsession
2424_LOGGER = logging .getLogger (__name__ )
2525STEP_USER_DATA_SCHEMA = vol .Schema (
2626 {
27- vol .Required (CONF_HOST ): str ,
28- vol .Required (CONF_API_KEY ): str ,
27+ vol .Required (CONF_URL ): str ,
28+ vol .Required (CONF_API_TOKEN ): str ,
2929 vol .Optional (CONF_VERIFY_SSL , default = True ): bool ,
3030 }
3131)
@@ -35,9 +35,11 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
3535 """Validate the user input allows us to connect."""
3636
3737 client = Portainer (
38- api_url = data [CONF_HOST ],
39- api_key = data [CONF_API_KEY ],
40- session = async_get_clientsession (hass = hass , verify_ssl = data [CONF_VERIFY_SSL ]),
38+ api_url = data [CONF_URL ],
39+ api_key = data [CONF_API_TOKEN ],
40+ session = async_get_clientsession (
41+ hass = hass , verify_ssl = data .get (CONF_VERIFY_SSL , True )
42+ ),
4143 )
4244 try :
4345 await client .get_endpoints ()
@@ -48,19 +50,21 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
4850 except PortainerTimeoutError as err :
4951 raise PortainerTimeout from err
5052
51- _LOGGER .debug ("Connected to Portainer API: %s" , data [CONF_HOST ])
53+ _LOGGER .debug ("Connected to Portainer API: %s" , data [CONF_URL ])
5254
5355
5456class PortainerConfigFlow (ConfigFlow , domain = DOMAIN ):
5557 """Handle a config flow for Portainer."""
5658
59+ VERSION = 2
60+
5761 async def async_step_user (
5862 self , user_input : dict [str , Any ] | None = None
5963 ) -> ConfigFlowResult :
6064 """Handle the initial step."""
6165 errors : dict [str , str ] = {}
6266 if user_input is not None :
63- self ._async_abort_entries_match ({CONF_HOST : user_input [CONF_HOST ]})
67+ self ._async_abort_entries_match ({CONF_URL : user_input [CONF_URL ]})
6468 try :
6569 await _validate_input (self .hass , user_input )
6670 except CannotConnect :
@@ -73,10 +77,10 @@ async def async_step_user(
7377 _LOGGER .exception ("Unexpected exception" )
7478 errors ["base" ] = "unknown"
7579 else :
76- await self .async_set_unique_id (user_input [CONF_API_KEY ])
80+ await self .async_set_unique_id (user_input [CONF_API_TOKEN ])
7781 self ._abort_if_unique_id_configured ()
7882 return self .async_create_entry (
79- title = user_input [CONF_HOST ], data = user_input
83+ title = user_input [CONF_URL ], data = user_input
8084 )
8185
8286 return self .async_show_form (
0 commit comments