Repository: home-assistant/core
File: homeassistant/components/lg_thinq/humidifier.py (Python)

Code before:
    def __init__(
        self,
        coordinator: DeviceDataUpdateCoordinator,
        entity_description: ThinQHumidifierEntityDescription,
        property_id: str,
    ) -> None:
        """Initialize a humidifier entity."""
        super().__init__(coordinator, entity_description, property_id)
        self._attr_available_modes = self.coordinator.data[
            self.entity_description.mode_key
        ].options

        if self.data.max is not None:
            self._attr_max_humidity = self.data.max
        if self.data.min is not None:
            self._attr_min_humidity = self.data.min
        self._target_humidity_step = self.data.step if self.data.step is not None else 1

    def _update_status(self) -> None:
        """Update status itself."""
        super()._update_status()

        self._attr_target_humidity = self.data.value
        self._attr_current_humidity = self.coordinator.data[
            self.entity_description.current_humidity_key
        ].value
        self._attr_is_on = self.coordinator.data[
            self.entity_description.operation_key
        ].is_on
        self._attr_mode = self.coordinator.data[self.entity_description.mode_key].value
        if self.is_on:
            self._attr_action = (
                HumidifierAction.DRYING
                if self.entity_description.device_class
                == HumidifierDeviceClass.DEHUMIDIFIER
                else HumidifierAction.HUMIDIFYING
            )
        else:
            self._attr_action = HumidifierAction.OFF

        _LOGGER.debug(
            "[%s:%s] update status: c:%s, t:%s, mode:%s, action:%s, is_on:%s",
            self.coordinator.device_name,
            self.property_id,
            self.current_humidity,
            self.target_humidity,
            self.mode,
            self.action,
            self.is_on,
        )


Review comment (suggestion):
When the dehumidifier is off and its humidity sensor is set to "Turns on with device" in the ThinQ App, the humidity sensor returns a value of 0% to Home Assistant.
We could correct the value here:
```suggestion
        current_humidity = self.coordinator.data[
            self.entity_description.current_humidity_key
        ].value
        self._attr_current_humidity = current_humidity if current_humidity != 0 else None
```

Code after:
    def __init__(
        self,
        coordinator: DeviceDataUpdateCoordinator,
        entity_description: ThinQHumidifierEntityDescription,
        property_id: str,
    ) -> None:
        """Initialize a humidifier entity."""
        super().__init__(coordinator, entity_description, property_id)
        self._attr_available_modes = self.coordinator.data[
            self.entity_description.mode_key
        ].options

        if self.data.max is not None:
            self._attr_max_humidity = self.data.max
        if self.data.min is not None:
            self._attr_min_humidity = self.data.min
        self._attr_target_humidity_step = (
            self.data.step if self.data.step is not None else 1
        )

    def _update_status(self) -> None:
        """Update status itself."""
        super()._update_status()

        self._attr_target_humidity = self.data.value
        self._attr_current_humidity = self.coordinator.data[
            self.entity_description.current_humidity_key
        ].value
        self._attr_is_on = self.coordinator.data[
            self.entity_description.operation_key
        ].is_on
        self._attr_mode = self.coordinator.data[self.entity_description.mode_key].value
        if self.is_on:
            self._attr_action = (
                HumidifierAction.DRYING
                if self.entity_description.device_class
                == HumidifierDeviceClass.DEHUMIDIFIER
                else HumidifierAction.HUMIDIFYING
            )
        else:
            self._attr_action = HumidifierAction.OFF

        _LOGGER.debug(
            "[%s:%s] update status: c:%s, t:%s, mode:%s, action:%s, is_on:%s",
            self.coordinator.device_name,
            self.property_id,
            self.current_humidity,
            self.target_humidity,
            self.mode,
            self.action,
            self.is_on,