Repository: home-assistant/core
File: homeassistant/components/cambridge_audio/number.py (Python)

Code before:
"""Support for Cambridge Audio switch entities."""

from collections.abc import Awaitable, Callable
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

from aiostreammagic import StreamMagicClient

from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from . import CambridgeAudioConfigEntry
from .entity import CambridgeAudioEntity, command

PARALLEL_UPDATES = 0


@dataclass(frozen=True, kw_only=True)
class CambridgeAudioNumberEntityDescription(NumberEntityDescription):
    """Describes Cambridge Audio switch entity."""

    load_fn: Callable[[StreamMagicClient], bool] = field(default=lambda _: True)
    value_fn: Callable[[StreamMagicClient], int]
    set_value_fn: Callable[[StreamMagicClient, int], Awaitable[None]]


def room_correction_intensity(client: StreamMagicClient) -> int:
    """Check if room correction is enabled."""
    if TYPE_CHECKING:
        assert client.audio.tilt_eq is not None
    return client.audio.tilt_eq.intensity


CONTROL_ENTITIES: tuple[CambridgeAudioNumberEntityDescription, ...] = (
    CambridgeAudioNumberEntityDescription(
        key="room_correction_intensity",
        translation_key="room_correction_intensity",
        entity_category=EntityCategory.CONFIG,
        native_min_value=-15,
        native_max_value=15,
        native_step=1,
        load_fn=lambda client: client.audio.tilt_eq is not None,
        value_fn=room_correction_intensity,
        set_value_fn=lambda client, value: client.set_room_correction_intensity(value),
    ),
)


Review comment (suggestion):
```suggestion
    load_fn: Callable[[StreamMagicClient], bool] = lambda _: True
```

Code after:
"""Support for Cambridge Audio number entities."""

from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING

from aiostreammagic import StreamMagicClient

from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from . import CambridgeAudioConfigEntry
from .entity import CambridgeAudioEntity, command

PARALLEL_UPDATES = 0


@dataclass(frozen=True, kw_only=True)
class CambridgeAudioNumberEntityDescription(NumberEntityDescription):
    """Describes Cambridge Audio number entity."""

    exists_fn: Callable[[StreamMagicClient], bool] = lambda _: True
    value_fn: Callable[[StreamMagicClient], int]
    set_value_fn: Callable[[StreamMagicClient, int], Awaitable[None]]


def room_correction_intensity(client: StreamMagicClient) -> int:
    """Get room correction intensity."""
    if TYPE_CHECKING:
        assert client.audio.tilt_eq is not None
    return client.audio.tilt_eq.intensity


CONTROL_ENTITIES: tuple[CambridgeAudioNumberEntityDescription, ...] = (
    CambridgeAudioNumberEntityDescription(
        key="room_correction_intensity",
        translation_key="room_correction_intensity",
        entity_category=EntityCategory.CONFIG,
        native_min_value=-15,
        native_max_value=15,
        native_step=1,
        exists_fn=lambda client: client.audio.tilt_eq is not None,
        value_fn=room_correction_intensity,
        set_value_fn=lambda client, value: client.set_room_correction_intensity(value),
    ),
)