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

Code before:
async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: SwitcherConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Switcher sensor from config entry."""

    @callback
    def async_add_sensors(coordinator: SwitcherDataUpdateCoordinator) -> None:
        """Add sensors from Switcher device."""
        if coordinator.data.device_type.category == DeviceCategory.POWER_PLUG:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in POWER_PLUG_SENSORS
            )
        elif coordinator.data.device_type.category == DeviceCategory.WATER_HEATER:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in WATER_HEATER_SENSORS
            )
        elif coordinator.data.device_type.category == DeviceCategory.THERMOSTAT:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in THERMOSTAT_SENSORS
            )
        elif coordinator.data.device_type.category == DeviceCategory.HEATER:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in HEATER_SENSORS
            )

    config_entry.async_on_unload(
        async_dispatcher_connect(hass, SIGNAL_DEVICE_ADD, async_add_sensors)
    )


class SwitcherSensorEntity(SwitcherEntity, SensorEntity):
    """Representation of a Switcher sensor entity."""

    def __init__(
        self,
        coordinator: SwitcherDataUpdateCoordinator,
        description: SwitcherSensorEntityDescription,
    ) -> None:
        """Initialize the entity."""
        super().__init__(coordinator)
        self.entity_description: SwitcherSensorEntityDescription = description

        self._attr_unique_id = (
            f"{coordinator.device_id}-{coordinator.mac_address}-{description.key}"
        )

Review comment (suggestion):
`elif coordinator.data.device_type.category in [DeviceCategory.WATER_HEATER, DeviceCategory.HEATER]`

Code after:
    hass: HomeAssistant,
    config_entry: SwitcherConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Switcher sensor from config entry."""

    @callback
    def async_add_sensors(coordinator: SwitcherDataUpdateCoordinator) -> None:
        """Add sensors from Switcher device."""
        if coordinator.data.device_type.category == DeviceCategory.POWER_PLUG:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in POWER_PLUG_SENSORS
            )
        elif coordinator.data.device_type.category in [
            DeviceCategory.WATER_HEATER,
            DeviceCategory.HEATER,
        ]:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in HEATER_SENSORS
            )
        elif coordinator.data.device_type.category == DeviceCategory.THERMOSTAT:
            async_add_entities(
                SwitcherSensorEntity(coordinator, description)
                for description in THERMOSTAT_SENSORS
            )

    config_entry.async_on_unload(
        async_dispatcher_connect(hass, SIGNAL_DEVICE_ADD, async_add_sensors)
    )


class SwitcherSensorEntity(SwitcherEntity, SensorEntity):
    """Representation of a Switcher sensor entity."""

    def __init__(
        self,
        coordinator: SwitcherDataUpdateCoordinator,
        description: SwitcherSensorEntityDescription,
    ) -> None:
        """Initialize the entity."""
        super().__init__(coordinator)
        self.entity_description: SwitcherSensorEntityDescription = description

        self._attr_unique_id = (
            f"{coordinator.device_id}-{coordinator.mac_address}-{description.key}"
        )

    @property
    def native_value(self) -> StateType: