2727class AzureStorageConfigFlow (ConfigFlow , domain = DOMAIN ):
2828 """Handle a config flow for azure storage."""
2929
30- def get_account_url (self , account_name : str ) -> str :
31- """Get the account URL."""
32- return f"https://{ account_name } .blob.core.windows.net/"
30+ async def get_container_client (
31+ self , account_name : str , container_name : str , storage_account_key : str
32+ ) -> ContainerClient :
33+ """Get the container client.
34+
35+ ContainerClient has a blocking call to open in cpython
36+ """
37+
38+ session = async_get_clientsession (self .hass )
39+
40+ def create_container_client () -> ContainerClient :
41+ return ContainerClient (
42+ account_url = f"https://{ account_name } .blob.core.windows.net/" ,
43+ container_name = container_name ,
44+ credential = storage_account_key ,
45+ transport = AioHttpTransport (session = session ),
46+ )
47+
48+ return await self .hass .async_add_executor_job (create_container_client )
3349
3450 async def validate_config (
3551 self , container_client : ContainerClient
@@ -58,11 +74,10 @@ async def async_step_user(
5874 self ._async_abort_entries_match (
5975 {CONF_ACCOUNT_NAME : user_input [CONF_ACCOUNT_NAME ]}
6076 )
61- container_client = ContainerClient (
62- account_url = self . get_account_url ( user_input [CONF_ACCOUNT_NAME ]) ,
77+ container_client = await self . get_container_client (
78+ account_name = user_input [CONF_ACCOUNT_NAME ],
6379 container_name = user_input [CONF_CONTAINER_NAME ],
64- credential = user_input [CONF_STORAGE_ACCOUNT_KEY ],
65- transport = AioHttpTransport (session = async_get_clientsession (self .hass )),
80+ storage_account_key = user_input [CONF_STORAGE_ACCOUNT_KEY ],
6681 )
6782 errors = await self .validate_config (container_client )
6883
@@ -99,12 +114,12 @@ async def async_step_reauth_confirm(
99114 reauth_entry = self ._get_reauth_entry ()
100115
101116 if user_input is not None :
102- container_client = ContainerClient (
103- account_url = self . get_account_url ( reauth_entry .data [CONF_ACCOUNT_NAME ]) ,
117+ container_client = await self . get_container_client (
118+ account_name = reauth_entry .data [CONF_ACCOUNT_NAME ],
104119 container_name = reauth_entry .data [CONF_CONTAINER_NAME ],
105- credential = user_input [CONF_STORAGE_ACCOUNT_KEY ],
106- transport = AioHttpTransport (session = async_get_clientsession (self .hass )),
120+ storage_account_key = user_input [CONF_STORAGE_ACCOUNT_KEY ],
107121 )
122+
108123 errors = await self .validate_config (container_client )
109124 if not errors :
110125 return self .async_update_reload_and_abort (
@@ -129,13 +144,10 @@ async def async_step_reconfigure(
129144 reconfigure_entry = self ._get_reconfigure_entry ()
130145
131146 if user_input is not None :
132- container_client = ContainerClient (
133- account_url = self .get_account_url (
134- reconfigure_entry .data [CONF_ACCOUNT_NAME ]
135- ),
147+ container_client = await self .get_container_client (
148+ account_name = reconfigure_entry .data [CONF_ACCOUNT_NAME ],
136149 container_name = user_input [CONF_CONTAINER_NAME ],
137- credential = user_input [CONF_STORAGE_ACCOUNT_KEY ],
138- transport = AioHttpTransport (session = async_get_clientsession (self .hass )),
150+ storage_account_key = user_input [CONF_STORAGE_ACCOUNT_KEY ],
139151 )
140152 errors = await self .validate_config (container_client )
141153 if not errors :
0 commit comments