Skip to content

Commit

Permalink
Merge branch 'dev' into acaia/0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj authored Nov 25, 2024
2 parents 2179860 + 2a52de4 commit 5eb4ff1
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 298 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:

async def async_handle_create_service(call: ServiceCall) -> None:
"""Service handler for creating backups."""
await backup_manager.async_create_backup(on_progress=None)
if backup_task := backup_manager.backup_task:
await backup_task
await backup_manager.async_create_backup()

hass.services.async_register(DOMAIN, "create", async_handle_create_service)

Expand Down
62 changes: 9 additions & 53 deletions homeassistant/components/backup/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import abc
import asyncio
from collections.abc import Callable
from dataclasses import asdict, dataclass
import hashlib
import io
Expand Down Expand Up @@ -35,13 +34,6 @@
BUF_SIZE = 2**20 * 4 # 4MB


@dataclass(slots=True)
class NewBackup:
"""New backup class."""

slug: str


@dataclass(slots=True)
class Backup:
"""Backup class."""
Expand All @@ -57,15 +49,6 @@ def as_dict(self) -> dict:
return {**asdict(self), "path": self.path.as_posix()}


@dataclass(slots=True)
class BackupProgress:
"""Backup progress class."""

done: bool
stage: str | None
success: bool | None


class BackupPlatformProtocol(Protocol):
"""Define the format that backup platforms can have."""

Expand All @@ -82,7 +65,7 @@ class BaseBackupManager(abc.ABC):
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize the backup manager."""
self.hass = hass
self.backup_task: asyncio.Task | None = None
self.backing_up = False
self.backups: dict[str, Backup] = {}
self.loaded_platforms = False
self.platforms: dict[str, BackupPlatformProtocol] = {}
Expand Down Expand Up @@ -150,12 +133,7 @@ async def async_restore_backup(self, slug: str, **kwargs: Any) -> None:
"""Restore a backup."""

@abc.abstractmethod
async def async_create_backup(
self,
*,
on_progress: Callable[[BackupProgress], None] | None,
**kwargs: Any,
) -> NewBackup:
async def async_create_backup(self, **kwargs: Any) -> Backup:
"""Generate a backup."""

@abc.abstractmethod
Expand Down Expand Up @@ -314,36 +292,17 @@ def _move_and_cleanup() -> None:
await self.hass.async_add_executor_job(_move_and_cleanup)
await self.load_backups()

async def async_create_backup(
self,
*,
on_progress: Callable[[BackupProgress], None] | None,
**kwargs: Any,
) -> NewBackup:
async def async_create_backup(self, **kwargs: Any) -> Backup:
"""Generate a backup."""
if self.backup_task:
if self.backing_up:
raise HomeAssistantError("Backup already in progress")
backup_name = f"Core {HAVERSION}"
date_str = dt_util.now().isoformat()
slug = _generate_slug(date_str, backup_name)
self.backup_task = self.hass.async_create_task(
self._async_create_backup(backup_name, date_str, slug, on_progress),
name="backup_manager_create_backup",
eager_start=False, # To ensure the task is not started before we return
)
return NewBackup(slug=slug)

async def _async_create_backup(
self,
backup_name: str,
date_str: str,
slug: str,
on_progress: Callable[[BackupProgress], None] | None,
) -> Backup:
"""Generate a backup."""
success = False
try:
self.backing_up = True
await self.async_pre_backup_actions()
backup_name = f"Core {HAVERSION}"
date_str = dt_util.now().isoformat()
slug = _generate_slug(date_str, backup_name)

backup_data = {
"slug": slug,
Expand All @@ -370,12 +329,9 @@ async def _async_create_backup(
if self.loaded_backups:
self.backups[slug] = backup
LOGGER.debug("Generated new backup with slug %s", slug)
success = True
return backup
finally:
if on_progress:
on_progress(BackupProgress(done=True, stage=None, success=success))
self.backup_task = None
self.backing_up = False
await self.async_post_backup_actions()

def _mkdir_and_generate_backup_contents(
Expand Down
11 changes: 4 additions & 7 deletions homeassistant/components/backup/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from homeassistant.core import HomeAssistant, callback

from .const import DATA_MANAGER, LOGGER
from .manager import BackupProgress


@callback
Expand Down Expand Up @@ -41,7 +40,7 @@ async def handle_info(
msg["id"],
{
"backups": list(backups.values()),
"backing_up": manager.backup_task is not None,
"backing_up": manager.backing_up,
},
)

Expand Down Expand Up @@ -114,11 +113,7 @@ async def handle_create(
msg: dict[str, Any],
) -> None:
"""Generate a backup."""

def on_progress(progress: BackupProgress) -> None:
connection.send_message(websocket_api.event_message(msg["id"], progress))

backup = await hass.data[DATA_MANAGER].async_create_backup(on_progress=on_progress)
backup = await hass.data[DATA_MANAGER].async_create_backup()
connection.send_result(msg["id"], backup)


Expand All @@ -132,6 +127,7 @@ async def handle_backup_start(
) -> None:
"""Backup start notification."""
manager = hass.data[DATA_MANAGER]
manager.backing_up = True
LOGGER.debug("Backup start notification")

try:
Expand All @@ -153,6 +149,7 @@ async def handle_backup_end(
) -> None:
"""Backup end notification."""
manager = hass.data[DATA_MANAGER]
manager.backing_up = False
LOGGER.debug("Backup end notification")

try:
Expand Down
46 changes: 26 additions & 20 deletions homeassistant/components/ecovacs/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from deebot_client.const import UNDEFINED, UndefinedType
from deebot_client.device import Device
from deebot_client.exceptions import DeebotError, InvalidAuthenticationError
from deebot_client.models import DeviceInfo
from deebot_client.mqtt_client import MqttClient, create_mqtt_config
from deebot_client.util import md5
from deebot_client.util.continents import get_continent
Expand Down Expand Up @@ -81,25 +80,32 @@ async def initialize(self) -> None:
try:
devices = await self._api_client.get_devices()
credentials = await self._authenticator.authenticate()
for device_config in devices:
if isinstance(device_config, DeviceInfo):
# MQTT device
device = Device(device_config, self._authenticator)
mqtt = await self._get_mqtt_client()
await device.initialize(mqtt)
self._devices.append(device)
else:
# Legacy device
bot = VacBot(
credentials.user_id,
EcoVacsAPI.REALM,
self._device_id[0:8],
credentials.token,
device_config,
self._continent,
monitor=True,
)
self._legacy_devices.append(bot)
for device_info in devices.mqtt:
device = Device(device_info, self._authenticator)
mqtt = await self._get_mqtt_client()
await device.initialize(mqtt)
self._devices.append(device)
for device_config in devices.xmpp:
bot = VacBot(
credentials.user_id,
EcoVacsAPI.REALM,
self._device_id[0:8],
credentials.token,
device_config,
self._continent,
monitor=True,
)
self._legacy_devices.append(bot)
for device_config in devices.not_supported:
_LOGGER.warning(
(
'Device "%s" not supported. Please add support for it to '
"https://github.com/DeebotUniverse/client.py: %s"
),
device_config["deviceName"],
device_config,
)

except InvalidAuthenticationError as ex:
raise ConfigEntryError("Invalid credentials") from ex
except DeebotError as ex:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ecovacs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/ecovacs",
"iot_class": "cloud_push",
"loggers": ["sleekxmppfs", "sucks", "deebot_client"],
"requirements": ["py-sucks==0.9.10", "deebot-client==8.4.1"]
"requirements": ["py-sucks==0.9.10", "deebot-client==9.0.0"]
}
16 changes: 2 additions & 14 deletions homeassistant/components/glances/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
HomeAssistantError,
)
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue

from .const import DOMAIN
from .coordinator import GlancesDataUpdateCoordinator

PLATFORMS = [Platform.SENSOR]
Expand Down Expand Up @@ -71,7 +69,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: GlancesConfigEntry) ->
async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
"""Return the api from glances_api."""
httpx_client = get_async_client(hass, verify_ssl=entry_data[CONF_VERIFY_SSL])
for version in (4, 3, 2):
for version in (4, 3):
api = Glances(
host=entry_data[CONF_HOST],
port=entry_data[CONF_PORT],
Expand All @@ -86,19 +84,9 @@ async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
except GlancesApiNoDataAvailable as err:
_LOGGER.debug("Failed to connect to Glances API v%s: %s", version, err)
continue
if version == 2:
async_create_issue(
hass,
DOMAIN,
"deprecated_version",
breaks_in_ha_version="2024.8.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_version",
)
_LOGGER.debug("Connected to Glances API v%s", version)
return api
raise ServerVersionMismatch("Could not connect to Glances API version 2, 3 or 4")
raise ServerVersionMismatch("Could not connect to Glances API version 3 or 4")


class ServerVersionMismatch(HomeAssistantError):
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/glances/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,5 @@
"name": "{sensor_label} TX"
}
}
},
"issues": {
"deprecated_version": {
"title": "Glances servers with version 2 is deprecated",
"description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update your server to Glances version 3 then reload the integration."
}
}
}
8 changes: 6 additions & 2 deletions homeassistant/components/homewizard/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ async def _async_update_data(self) -> DeviceResponseEntry:
)

except RequestError as ex:
raise UpdateFailed(ex) from ex
raise UpdateFailed(
ex, translation_domain=DOMAIN, translation_key="communication_error"
) from ex

except DisabledError as ex:
if not self.api_disabled:
Expand All @@ -79,7 +81,9 @@ async def _async_update_data(self) -> DeviceResponseEntry:
self.config_entry.entry_id
)

raise UpdateFailed(ex) from ex
raise UpdateFailed(
ex, translation_domain=DOMAIN, translation_key="api_disabled"
) from ex

self.api_disabled = False

Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/homewizard/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ rules:
entity-device-class: done
entity-disabled-by-default: done
entity-translations: done
exception-translations:
status: todo
comment: |
While the integration provides some of the exception translations, the
translation for the error raised in the update error of the coordinator
is missing.
exception-translations: done
icon-translations: done
reconfiguration-flow: todo
repair-issues:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homewizard/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"error": {
"api_not_enabled": "The API is not enabled. Enable API in the HomeWizard Energy App under settings",
"api_not_enabled": "The local API is disabled. Go to the HomeWizard Energy app and enable the API in the device settings.",
"network_error": "Device unreachable, make sure that you have entered the correct IP address and that the device is available in your network"
},
"abort": {
Expand Down Expand Up @@ -123,7 +123,7 @@
},
"exceptions": {
"api_disabled": {
"message": "The local API of the HomeWizard device is disabled"
"message": "The local API is disabled."
},
"communication_error": {
"message": "An error occurred while communicating with HomeWizard device"
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/palazzetti/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ def __init__(self, coordinator: PalazzettiDataUpdateCoordinator) -> None:
if client.has_fan_auto:
self._attr_fan_modes.append(FAN_AUTO)

@property
def available(self) -> bool:
"""Is the entity available."""
return super().available and self.coordinator.client.connected

@property
def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat or off mode."""
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/palazzetti/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ def __init__(self, coordinator: PalazzettiDataUpdateCoordinator) -> None:
sw_version=client.sw_version,
hw_version=client.hw_version,
)

@property
def available(self) -> bool:
"""Is the entity available."""
return super().available and self.coordinator.client.connected
2 changes: 1 addition & 1 deletion homeassistant/components/palazzetti/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ rules:
comment: |
This integration does not have configuration.
docs-installation-parameters: todo
entity-unavailable: todo
entity-unavailable: done
integration-owner: done
log-when-unavailable: done
parallel-updates: todo
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ debugpy==1.8.6
# decora==0.6

# homeassistant.components.ecovacs
deebot-client==8.4.1
deebot-client==9.0.0

# homeassistant.components.ihc
# homeassistant.components.namecheapdns
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ dbus-fast==2.24.3
debugpy==1.8.6

# homeassistant.components.ecovacs
deebot-client==8.4.1
deebot-client==9.0.0

# homeassistant.components.ihc
# homeassistant.components.namecheapdns
Expand Down
Loading

0 comments on commit 5eb4ff1

Please sign in to comment.