1 """KNX Keyring handler."""
4 from pathlib
import Path
6 from typing
import Final
8 from xknx.exceptions.exception
import InvalidSecureConfiguration
9 from xknx.secure.keyring
import Keyring, sync_load_keyring
15 from ..const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
20 DEFAULT_KNX_KEYRING_FILENAME: Final =
"keyring.knxkeys"
24 hass: HomeAssistant, uploaded_file_id: str, password: str
26 """Validate the uploaded file and move it to the storage directory.
28 Return a Keyring object.
29 Raises InvalidSecureConfiguration if the file or password is invalid.
32 def _process_upload() -> Keyring:
35 keyring = sync_load_keyring(
39 except InvalidSecureConfiguration
as err:
42 dest_path = Path(hass.config.path(STORAGE_DIR, DOMAIN))
43 dest_path.mkdir(exist_ok=
True)
44 dest_file = dest_path / DEFAULT_KNX_KEYRING_FILENAME
45 shutil.move(file_path, dest_file)
48 return await hass.async_add_executor_job(_process_upload)
Iterator[Path] process_uploaded_file(HomeAssistant hass, str file_id)
Keyring save_uploaded_knxkeys_file(HomeAssistant hass, str uploaded_file_id, str password)