Repository: home-assistant/core
File: homeassistant/components/bang_olufsen/sensor.py (Python)

Code before:
    if await supports_battery(config_entry.runtime_data.client):
        entities.append(BeoSensorBatteryLevel(config_entry))

    # Add any Beoremote One remotes
    entities.extend(
        [
            BeoSensorRemoteBatteryLevel(config_entry, remote)
            for remote in (await get_remotes(config_entry.runtime_data.client))
        ]
    )

    async_add_entities(entities, update_before_add=True)


class BeoSensor(SensorEntity, BeoEntity):
    """Base Bang & Olufsen Sensor."""

    def __init__(self, config_entry: BeoConfigEntry) -> None:
        """Initialize Sensor."""
        super().__init__(config_entry, config_entry.runtime_data.client)


class BeoSensorBatteryLevel(BeoSensor):
    """Battery level Sensor for Mozart devices."""

    _attr_native_unit_of_measurement = "%"
    _attr_translation_key = "battery_level"
    _attr_state_class = SensorStateClass.MEASUREMENT

    def __init__(self, config_entry: BeoConfigEntry) -> None:
        """Init the battery level Sensor."""
        super().__init__(config_entry)

        self._attr_device_class = SensorDeviceClass.BATTERY
        self._attr_unique_id = f"{self._unique_id}_battery_level"

    async def async_added_to_hass(self) -> None:
        """Turn on the dispatchers."""
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass,
                f"{DOMAIN}_{self._unique_id}_{CONNECTION_STATUS}",
                self._async_update_connection_state,
            )
        )
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass,
                f"{DOMAIN}_{self._unique_id}_{WebsocketNotification.BATTERY}",
                self._update_battery,
            )

Review comment (suggestion):
```suggestion
    _attr_native_unit_of_measurement = PERCENTAGE
```

Code after:
    # Check for Mozart device with battery
    if await supports_battery(config_entry.runtime_data.client):
        entities.append(BeoSensorBatteryLevel(config_entry))

    # Add any Beoremote One remotes
    entities.extend(
        [
            BeoSensorRemoteBatteryLevel(config_entry, remote)
            for remote in (await get_remotes(config_entry.runtime_data.client))
        ]
    )

    async_add_entities(entities, update_before_add=True)


class BeoSensor(SensorEntity, BeoEntity):
    """Base Bang & Olufsen Sensor."""

    def __init__(self, config_entry: BeoConfigEntry) -> None:
        """Initialize Sensor."""
        super().__init__(config_entry, config_entry.runtime_data.client)


class BeoSensorBatteryLevel(BeoSensor):
    """Battery level Sensor for Mozart devices."""

    _attr_device_class = SensorDeviceClass.BATTERY
    _attr_native_unit_of_measurement = PERCENTAGE
    _attr_state_class = SensorStateClass.MEASUREMENT

    def __init__(self, config_entry: BeoConfigEntry) -> None:
        """Init the battery level Sensor."""
        super().__init__(config_entry)

        self._attr_unique_id = f"{self._unique_id}_battery_level"

    async def async_added_to_hass(self) -> None:
        """Turn on the dispatchers."""
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass,
                f"{DOMAIN}_{self._unique_id}_{CONNECTION_STATUS}",
                self._async_update_connection_state,
            )
        )
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass,
                f"{DOMAIN}_{self._unique_id}_{WebsocketNotification.BATTERY}",
                self._update_battery,
            )