Skip to content

Commit f6b1b3b

Browse files
Add Scaleway Object Storage backup integration
1 parent c05c2b7 commit f6b1b3b

24 files changed

+3493
-0
lines changed

.strict-typing

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ homeassistant.components.ruuvi_gateway.*
481481
homeassistant.components.ruuvitag_ble.*
482482
homeassistant.components.samsungtv.*
483483
homeassistant.components.saunum.*
484+
homeassistant.components.scaleway_object_storage.*
484485
homeassistant.components.scene.*
485486
homeassistant.components.schedule.*
486487
homeassistant.components.schlage.*

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""The Scaleway Object Storage integration."""
2+
3+
from typing import TYPE_CHECKING
4+
5+
from homeassistant.config_entries import ConfigEntry
6+
from homeassistant.exceptions import (
7+
ConfigEntryAuthFailed,
8+
ConfigEntryError,
9+
ConfigEntryNotReady,
10+
)
11+
from homeassistant.helpers import aiohttp_client
12+
13+
if TYPE_CHECKING:
14+
from aiohttp_s3_client import S3Client
15+
16+
from homeassistant.core import HomeAssistant
17+
18+
from . import exceptions, helpers
19+
from .const import DATA_BACKUP_AGENT_LISTENERS, DOMAIN
20+
21+
type ScalewayConfigEntry = ConfigEntry[S3Client]
22+
23+
24+
async def async_setup_entry(hass: HomeAssistant, entry: ScalewayConfigEntry) -> bool:
25+
"""Set up an integration config entry."""
26+
session = aiohttp_client.async_get_clientsession(hass)
27+
try:
28+
await helpers.check_connection(session, entry.data)
29+
except ConfigEntryNotReady, ConfigEntryError, ConfigEntryAuthFailed:
30+
# Re-raise as they are
31+
raise
32+
except exceptions.ScalewayException as e:
33+
# All other exceptions are translated
34+
raise ConfigEntryError(
35+
translation_domain=DOMAIN,
36+
translation_key=e.translation_key,
37+
translation_placeholders=e.translation_placeholders,
38+
) from e
39+
40+
entry.runtime_data = helpers.create_client(session, entry.data)
41+
42+
# Notify backup listeners
43+
def notify_backup_listeners() -> None:
44+
listeners = hass.data.get(DATA_BACKUP_AGENT_LISTENERS, [])
45+
for listener in list(listeners):
46+
listener()
47+
48+
entry.async_on_unload(entry.async_on_state_change(notify_backup_listeners))
49+
50+
return True
51+
52+
53+
async def async_unload_entry(hass: HomeAssistant, entry: ScalewayConfigEntry) -> bool:
54+
"""Unload a config entry."""
55+
return True

0 commit comments

Comments
 (0)