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

Code before:
    UnitOfTime,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .entity import MatterEntity, MatterEntityDescription
from .helpers import get_matter
from .models import MatterDiscoverySchema

# intensities in inovelli LEDs are represented by a number from 0 to 75 but only 11
# values are actually used when one of 11 levels is set by manually configuring the dimmer
INOVELLI_LED_INTENSITY_MAP = {
    0: 0,
    1: 1,
    2: 8,
    3: 15,
    4: 24,
    5: 33,
    6: 42,
    7: 50,
    8: 59,
    9: 68,
    10: 75,
}

INOVELLI_LED_INTENSITY_MAP_REVERSE = {}
for i in range(10):
    start = INOVELLI_LED_INTENSITY_MAP[i]
    end = INOVELLI_LED_INTENSITY_MAP[i + 1]
    for j in range(start, end):
        INOVELLI_LED_INTENSITY_MAP_REVERSE[j] = i
INOVELLI_LED_INTENSITY_MAP_REVERSE[INOVELLI_LED_INTENSITY_MAP[10]] = 10


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: ConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Matter Number Input from Config Entry."""
    matter = get_matter(hass)
    matter.register_platform_handler(Platform.NUMBER, async_add_entities)


@dataclass(frozen=True)
class MatterNumberEntityDescription(NumberEntityDescription, MatterEntityDescription):
    """Describe Matter Number Input entities."""


@dataclass(frozen=True, kw_only=True)
class MatterRangeNumberEntityDescription(

Review comment (suggestion):
We can simply iterate `INOVELLI_LED_INTENSITY_MAP` to create the reverse map. Search for reverse in the project source to find examples.

Code after:
    UnitOfTime,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .entity import MatterEntity, MatterEntityDescription
from .helpers import get_matter
from .models import MatterDiscoverySchema


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: ConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Matter Number Input from Config Entry."""
    matter = get_matter(hass)
    matter.register_platform_handler(Platform.NUMBER, async_add_entities)


@dataclass(frozen=True)
class MatterNumberEntityDescription(NumberEntityDescription, MatterEntityDescription):
    """Describe Matter Number Input entities."""


@dataclass(frozen=True, kw_only=True)
class MatterRangeNumberEntityDescription(
    NumberEntityDescription, MatterEntityDescription
):
    """Describe Matter Number Input entities with min and max values."""

    ha_to_device: Callable[[Any], Any]

    # attribute descriptors to get the min and max value
    min_attribute: type[ClusterAttributeDescriptor]
    max_attribute: type[ClusterAttributeDescriptor]

    # command: a custom callback to create the command to send to the device
    # the callback's argument will be the index of the selected list value
    command: Callable[[int], ClusterCommand]


class MatterNumber(MatterEntity, NumberEntity):
    """Representation of a Matter Attribute as a Number entity."""

    entity_description: MatterNumberEntityDescription

    async def async_set_native_value(self, value: float) -> None:
        """Update the current value."""
        sendvalue = int(value)
        if value_convert := self.entity_description.ha_to_device: