1 """The Nextcloud integration."""
5 from nextcloudmonitor
import (
7 NextcloudMonitorAuthorizationError,
8 NextcloudMonitorConnectionError,
9 NextcloudMonitorRequestError,
24 from .coordinator
import NextcloudDataUpdateCoordinator
26 PLATFORMS = (Platform.SENSOR, Platform.BINARY_SENSOR, Platform.UPDATE)
29 _LOGGER = logging.getLogger(__name__)
31 type NextcloudConfigEntry = ConfigEntry[NextcloudDataUpdateCoordinator]
35 """Set up the Nextcloud integration."""
38 entity_reg = er.async_get(hass)
39 entities: list[er.RegistryEntry] = er.async_entries_for_config_entry(
40 entity_reg, entry.entry_id
42 for entity
in entities:
43 old_uid_start = f
"{entry.data[CONF_URL]}#nextcloud_"
44 new_uid_start = f
"{entry.entry_id}#"
45 if entity.unique_id.startswith(old_uid_start):
46 new_uid = entity.unique_id.replace(old_uid_start, new_uid_start)
47 _LOGGER.debug(
"migrate unique id '%s' to '%s'", entity.unique_id, new_uid)
48 entity_reg.async_update_entity(entity.entity_id, new_unique_id=new_uid)
51 return NextcloudMonitor(
53 entry.data[CONF_USERNAME],
54 entry.data[CONF_PASSWORD],
55 verify_ssl=entry.data[CONF_VERIFY_SSL],
60 ncm = await hass.async_add_executor_job(_connect_nc)
61 except NextcloudMonitorAuthorizationError
as ex:
62 raise ConfigEntryAuthFailed
from ex
63 except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError)
as ex:
64 raise ConfigEntryNotReady
from ex
72 await coordinator.async_config_entry_first_refresh()
74 entry.runtime_data = coordinator
76 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
82 """Unload Nextcloud integration."""
83 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, NextcloudConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, NextcloudConfigEntry entry)