Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
uses: actions/[email protected]

- name: Initialize CodeQL
uses: github/codeql-action/[email protected].0
uses: github/codeql-action/[email protected].1
with:
languages: python

- name: Perform CodeQL Analysis
uses: github/codeql-action/[email protected].0
uses: github/codeql-action/[email protected].1
with:
category: "/language:python"
5 changes: 0 additions & 5 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
from .exceptions import HomeAssistantError
from .helpers import (
area_registry,
backup,
category_registry,
config_validation as cv,
device_registry,
Expand Down Expand Up @@ -880,10 +879,6 @@ async def _async_set_up_integrations(
if "recorder" in all_domains:
recorder.async_initialize_recorder(hass)

# Initialize backup
if "backup" in all_domains:
backup.async_initialize_backup(hass)

stages: list[tuple[str, set[str], int | None]] = [
*(
(name, domain_group, timeout)
Expand Down
27 changes: 16 additions & 11 deletions homeassistant/components/backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from homeassistant.config_entries import SOURCE_SYSTEM
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, discovery_flow
from homeassistant.helpers.backup import DATA_BACKUP
from homeassistant.helpers.hassio import is_hassio
from homeassistant.helpers.typing import ConfigType

Expand Down Expand Up @@ -37,7 +37,6 @@
IdleEvent,
IncorrectPasswordError,
ManagerBackup,
ManagerStateEvent,
NewBackup,
RestoreBackupEvent,
RestoreBackupStage,
Expand Down Expand Up @@ -72,12 +71,12 @@
"IncorrectPasswordError",
"LocalBackupAgent",
"ManagerBackup",
"ManagerStateEvent",
"NewBackup",
"RestoreBackupEvent",
"RestoreBackupStage",
"RestoreBackupState",
"WrittenBackup",
"async_get_manager",
"suggested_filename",
"suggested_filename_from_name_date",
]
Expand All @@ -104,13 +103,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:

backup_manager = BackupManager(hass, reader_writer)
hass.data[DATA_MANAGER] = backup_manager
try:
await backup_manager.async_setup()
except Exception as err:
hass.data[DATA_BACKUP].manager_ready.set_exception(err)
raise
else:
hass.data[DATA_BACKUP].manager_ready.set_result(None)
await backup_manager.async_setup()

async_register_websocket_handlers(hass, with_hassio)

Expand Down Expand Up @@ -143,3 +136,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: BackupConfigEntry) -> bo
async def async_unload_entry(hass: HomeAssistant, entry: BackupConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)


@callback
def async_get_manager(hass: HomeAssistant) -> BackupManager:
"""Get the backup manager instance.

Raises HomeAssistantError if the backup integration is not available.
"""
if DATA_MANAGER not in hass.data:
raise HomeAssistantError("Backup integration is not available")

return hass.data[DATA_MANAGER]
38 changes: 0 additions & 38 deletions homeassistant/components/backup/basic_websocket.py

This file was deleted.

8 changes: 2 additions & 6 deletions homeassistant/components/backup/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.backup import (
async_subscribe_events,
async_subscribe_platform_events,
)
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DOMAIN, LOGGER
Expand Down Expand Up @@ -56,8 +52,8 @@ def __init__(
update_interval=None,
)
self.unsubscribe: list[Callable[[], None]] = [
async_subscribe_events(hass, self._on_event),
async_subscribe_platform_events(hass, self._on_event),
backup_manager.async_subscribe_events(self._on_event),
backup_manager.async_subscribe_platform_events(self._on_event),
]

self.backup_manager = backup_manager
Expand Down
37 changes: 30 additions & 7 deletions homeassistant/components/backup/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
issue_registry as ir,
start,
)
from homeassistant.helpers.backup import DATA_BACKUP
from homeassistant.helpers.json import json_bytes
from homeassistant.util import dt as dt_util, json as json_util

Expand Down Expand Up @@ -372,12 +371,10 @@ def __init__(self, hass: HomeAssistant, reader_writer: BackupReaderWriter) -> No
# Latest backup event and backup event subscribers
self.last_event: ManagerStateEvent = BlockedEvent()
self.last_action_event: ManagerStateEvent | None = None
self._backup_event_subscriptions = hass.data[
DATA_BACKUP
].backup_event_subscriptions
self._backup_platform_event_subscriptions = hass.data[
DATA_BACKUP
].backup_platform_event_subscriptions
self._backup_event_subscriptions: list[Callable[[ManagerStateEvent], None]] = []
self._backup_platform_event_subscriptions: list[
Callable[[BackupPlatformEvent], None]
] = []

async def async_setup(self) -> None:
"""Set up the backup manager."""
Expand Down Expand Up @@ -1385,6 +1382,32 @@ def async_on_backup_event(
for subscription in self._backup_event_subscriptions:
subscription(event)

@callback
def async_subscribe_events(
self,
on_event: Callable[[ManagerStateEvent], None],
) -> Callable[[], None]:
"""Subscribe events."""

def remove_subscription() -> None:
self._backup_event_subscriptions.remove(on_event)

self._backup_event_subscriptions.append(on_event)
return remove_subscription

@callback
def async_subscribe_platform_events(
self,
on_event: Callable[[BackupPlatformEvent], None],
) -> Callable[[], None]:
"""Subscribe to backup platform events."""

def remove_subscription() -> None:
self._backup_platform_event_subscriptions.remove(on_event)

self._backup_platform_event_subscriptions.append(on_event)
return remove_subscription

def _create_automatic_backup_failed_issue(
self, translation_key: str, translation_placeholders: dict[str, str] | None
) -> None:
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/backup/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.backup import async_get_manager as async_get_backup_manager

from . import BackupManager, Folder, IncorrectPasswordError, http as backup_http
from . import (
BackupManager,
Folder,
IncorrectPasswordError,
async_get_manager,
http as backup_http,
)

if TYPE_CHECKING:
from homeassistant.components.onboarding import OnboardingStoreData
Expand Down Expand Up @@ -54,7 +59,7 @@ async def with_backup(
if self._data["done"]:
raise HTTPUnauthorized

manager = await async_get_backup_manager(request.app[KEY_HASS])
manager = async_get_manager(request.app[KEY_HASS])
return await func(self, manager, request, *args, **kwargs)

return with_backup
Expand Down
26 changes: 25 additions & 1 deletion homeassistant/components/backup/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

from .config import Day, ScheduleRecurrence
from .const import DATA_MANAGER, LOGGER
from .manager import DecryptOnDowloadNotSupported, IncorrectPasswordError
from .manager import (
DecryptOnDowloadNotSupported,
IncorrectPasswordError,
ManagerStateEvent,
)
from .models import BackupNotFound, Folder


Expand All @@ -30,6 +34,7 @@ def async_register_websocket_handlers(hass: HomeAssistant, with_hassio: bool) ->
websocket_api.async_register_command(hass, handle_create_with_automatic_settings)
websocket_api.async_register_command(hass, handle_delete)
websocket_api.async_register_command(hass, handle_restore)
websocket_api.async_register_command(hass, handle_subscribe_events)

websocket_api.async_register_command(hass, handle_config_info)
websocket_api.async_register_command(hass, handle_config_update)
Expand Down Expand Up @@ -417,3 +422,22 @@ def handle_config_update(
changes.pop("type")
manager.config.update(**changes)
connection.send_result(msg["id"])


@websocket_api.require_admin
@websocket_api.websocket_command({vol.Required("type"): "backup/subscribe_events"})
@websocket_api.async_response
async def handle_subscribe_events(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Subscribe to backup events."""

def on_event(event: ManagerStateEvent) -> None:
connection.send_message(websocket_api.event_message(msg["id"], event))

manager = hass.data[DATA_MANAGER]
on_event(manager.last_event)
connection.subscriptions[msg["id"]] = manager.async_subscribe_events(on_event)
connection.send_result(msg["id"])
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
RestoreBackupStage,
RestoreBackupState,
WrittenBackup,
async_get_manager as async_get_backup_manager,
suggested_filename as suggested_backup_filename,
suggested_filename_from_name_date,
)
from homeassistant.const import __version__ as HAVERSION
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.backup import async_get_manager as async_get_backup_manager
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.util import dt as dt_util
from homeassistant.util.enum import try_parse_enum
Expand Down Expand Up @@ -839,7 +839,7 @@ def _delete_filter(

async def backup_core_before_update(hass: HomeAssistant) -> None:
"""Prepare for updating core."""
backup_manager = await async_get_backup_manager(hass)
backup_manager = async_get_backup_manager(hass)
client = get_supervisor_client(hass)

try:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
EVENT_HOMEASSISTANT_START,
SERVICE_RELOAD,
STATE_HOME,
STATE_NOT_HOME,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
Expand Down Expand Up @@ -526,7 +525,7 @@ def _update_state(self) -> None:
latest_gps = _get_latest(latest_gps, state)
elif state.state == STATE_HOME:
latest_non_gps_home = _get_latest(latest_non_gps_home, state)
elif state.state == STATE_NOT_HOME:
else:
latest_not_home = _get_latest(latest_not_home, state)

if latest_non_gps_home:
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/plugwise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) ->
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, str(coordinator.api.gateway_id))},
manufacturer="Plugwise",
model=coordinator.api.smile_model,
model_id=coordinator.api.smile_model_id,
name=coordinator.api.smile_name,
sw_version=str(coordinator.api.smile_version),
model=coordinator.api.smile.model,
model_id=coordinator.api.smile.model_id,
name=coordinator.api.smile.name,
sw_version=str(coordinator.api.smile.version),
) # required for adding the entity-less P1 Gateway

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/plugwise/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _add_entities() -> None:
if not coordinator.new_devices:
return

if coordinator.api.smile_name == "Adam":
if coordinator.api.smile.name == "Adam":
async_add_entities(
PlugwiseClimateEntity(coordinator, device_id)
for device_id in coordinator.new_devices
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
if (
self.coordinator.api.cooling_present
and coordinator.api.smile_name != "Adam"
and coordinator.api.smile.name != "Adam"
):
self._attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/plugwise/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ async def async_step_user(
api, errors = await verify_connection(self.hass, user_input)
if api:
await self.async_set_unique_id(
api.smile_hostname or api.gateway_id,
api.smile.hostname or api.gateway_id,
raise_on_progress=False,
)
self._abort_if_unique_id_configured()
return self.async_create_entry(title=api.smile_name, data=user_input)
return self.async_create_entry(title=api.smile.name, data=user_input)

return self.async_show_form(
step_id=SOURCE_USER,
Expand Down Expand Up @@ -236,7 +236,7 @@ async def async_step_reconfigure(
api, errors = await verify_connection(self.hass, full_input)
if api:
await self.async_set_unique_id(
api.smile_hostname or api.gateway_id,
api.smile.hostname or api.gateway_id,
raise_on_progress=False,
)
self._abort_if_unique_id_mismatch(reason="not_the_same_smile")
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/plugwise/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
manufacturer=data.get("vendor"),
model=data.get("model"),
model_id=data.get("model_id"),
name=coordinator.api.smile_name,
name=coordinator.api.smile.name,
sw_version=data.get("firmware"),
hw_version=data.get("hardware"),
)
Expand Down
Loading
Loading