mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Avoid mutating entity descriptions in lidarr (#105628)
This commit is contained in:
parent
abac68f158
commit
7ab003c746
@ -2,8 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from copy import deepcopy
|
import dataclasses
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Any, Generic
|
from typing import Any, Generic
|
||||||
|
|
||||||
from aiopyarr import LidarrQueue, LidarrQueueItem, LidarrRootFolder
|
from aiopyarr import LidarrQueue, LidarrQueueItem, LidarrRootFolder
|
||||||
@ -40,21 +39,23 @@ def get_modified_description(
|
|||||||
description: LidarrSensorEntityDescription[T], mount: LidarrRootFolder
|
description: LidarrSensorEntityDescription[T], mount: LidarrRootFolder
|
||||||
) -> tuple[LidarrSensorEntityDescription[T], str]:
|
) -> tuple[LidarrSensorEntityDescription[T], str]:
|
||||||
"""Return modified description and folder name."""
|
"""Return modified description and folder name."""
|
||||||
desc = deepcopy(description)
|
|
||||||
name = mount.path.rsplit("/")[-1].rsplit("\\")[-1]
|
name = mount.path.rsplit("/")[-1].rsplit("\\")[-1]
|
||||||
desc.key = f"{description.key}_{name}"
|
desc = dataclasses.replace(
|
||||||
desc.name = f"{description.name} {name}".capitalize()
|
description,
|
||||||
|
key=f"{description.key}_{name}",
|
||||||
|
name=f"{description.name} {name}".capitalize(),
|
||||||
|
)
|
||||||
return desc, name
|
return desc, name
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclasses.dataclass
|
||||||
class LidarrSensorEntityDescriptionMixIn(Generic[T]):
|
class LidarrSensorEntityDescriptionMixIn(Generic[T]):
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_fn: Callable[[T, str], str | int]
|
value_fn: Callable[[T, str], str | int]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclasses.dataclass
|
||||||
class LidarrSensorEntityDescription(
|
class LidarrSensorEntityDescription(
|
||||||
SensorEntityDescription, LidarrSensorEntityDescriptionMixIn[T], Generic[T]
|
SensorEntityDescription, LidarrSensorEntityDescriptionMixIn[T], Generic[T]
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user