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

Code before:

async def async_setup_entry(
    hass: HomeAssistant,
    entry: ZinvoltConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Initialize the entries."""

    async_add_entities(
        ZinvoltBatteryStateNumber(coordinator, description)
        for description in NUMBERS
        for coordinator in entry.runtime_data.values()
    )


class ZinvoltBatteryStateNumber(ZinvoltEntity, NumberEntity):
    """Zinvolt number."""

    entity_description: ZinvoltBatteryStateDescription

    def __init__(
        self,
        coordinator: ZinvoltDeviceCoordinator,
        description: ZinvoltBatteryStateDescription,
    ) -> None:
        """Initialize the sensor."""
        super().__init__(coordinator)
        self.entity_description = description
        self._attr_unique_id = f"{coordinator.data.serial_number}.{description.key}"

    @property
    def native_max_value(self) -> float:
        """Return the native maximum value."""
        if self.entity_description.max_fn is None:
            return super().native_max_value
        return self.entity_description.max_fn(self.coordinator.data)

    @property
    def native_value(self) -> float:
        """Return the state of the sensor."""
        return self.entity_description.value_fn(self.coordinator.data)

    async def async_set_native_value(self, value: float) -> None:
        """Set the state of the sensor."""
        await self.entity_description.set_value_fn(
            self.coordinator.client, self.coordinator.battery_id, int(value)
        )


Review comment (suggestion):
```suggestion
        """Initialize the number."""
```

Code after:

async def async_setup_entry(
    hass: HomeAssistant,
    entry: ZinvoltConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Initialize the entries."""

    async_add_entities(
        ZinvoltBatteryStateNumber(coordinator, description)
        for description in NUMBERS
        for coordinator in entry.runtime_data.values()
    )


class ZinvoltBatteryStateNumber(ZinvoltEntity, NumberEntity):
    """Zinvolt number."""

    entity_description: ZinvoltBatteryStateDescription

    def __init__(
        self,
        coordinator: ZinvoltDeviceCoordinator,
        description: ZinvoltBatteryStateDescription,
    ) -> None:
        """Initialize the number."""
        super().__init__(coordinator)
        self.entity_description = description
        self._attr_unique_id = f"{coordinator.data.serial_number}.{description.key}"

    @property
    def native_max_value(self) -> float:
        """Return the native maximum value."""
        if self.entity_description.max_fn is None:
            return super().native_max_value
        return self.entity_description.max_fn(self.coordinator.data)

    @property
    def native_value(self) -> float:
        """Return the state of the sensor."""
        return self.entity_description.value_fn(self.coordinator.data)

    async def async_set_native_value(self, value: float) -> None:
        """Set the state of the sensor."""
        await self.entity_description.set_value_fn(
            self.coordinator.client, self.coordinator.battery_id, int(value)
        )