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

Code before:
            return

        try:
            self._accumulated_value = float(raw_value)
            LOGGER.debug(
                "Initialized accumulated value from device for %s: %s",
                self.unique_id,
                self._accumulated_value,
            )
        except (ValueError, TypeError) as err:
            LOGGER.error(
                "Could not initialize accumulated value for %s: %s",
                self.unique_id,
                err,
            )

    async def _handle_state_update(
        self,
        updated_status_properties: list[str] | None,
        dp_timestamps: dict | None = None,
    ) -> None:
        """Handle state update from device."""
        if self._is_delta_report:
            self._process_delta_update(updated_status_properties, dp_timestamps)

        await super()._handle_state_update(updated_status_properties, dp_timestamps)

    def _process_delta_update(
        self,
        updated_status_properties: list[str] | None,
        dp_timestamps: dict | None,
    ) -> None:
        """Process delta report update by accumulating the value."""
        dpcode = self.entity_description.dpcode or self.entity_description.key

        if (
            updated_status_properties is not None
            and dpcode not in updated_status_properties
        ):
            return

        current_timestamp = dp_timestamps.get(dpcode) if dp_timestamps else None

        # Skip duplicate updates with same timestamp
        if (
            current_timestamp is not None
            and current_timestamp == self._last_dp_timestamp
        ):
            LOGGER.debug(
                "Skipping duplicate update for %s (same timestamp: %s)",
                self.unique_id,

Review comment (suggestion):
I think we can skip the update altogether if skip_update applies (= not in updated_status_properties)
Similar to #160404

```suggestion
        if self._dpcode_wrapper.skip_update(self.device, updated_status_properties):
            return

        if self._is_delta_report:
            self._process_delta_update(updated_status_properties, dp_timestamps)

        self.async_write_ha_state()
```

Code after:
                    "Device class %s ignored for incompatible unit %s in sensor entity %s",
                    self.device_class,
                    self.native_unit_of_measurement,
                    self.unique_id,
                )
                self._attr_device_class = None
                self._attr_suggested_unit_of_measurement = None
                return

            uoms = DEVICE_CLASS_UNITS[self.device_class]
            uom = uoms.get(self.native_unit_of_measurement) or uoms.get(
                self.native_unit_of_measurement.lower()
            )

            # Unknown unit of measurement, device class should not be used.
            if uom is None:
                self._attr_device_class = None
                self._attr_suggested_unit_of_measurement = None
                return

            # Found unit of measurement, use the standardized Unit
            # Use the target conversion unit (if set)
            self._attr_native_unit_of_measurement = uom.unit

    @property
    def native_value(self) -> StateType:
        """Return the value reported by the sensor."""
        return self._read_wrapper(self._dpcode_wrapper)

    async def _handle_state_update(
        self,
        updated_status_properties: list[str] | None,
        dp_timestamps: dict[str, int] | None,
    ) -> None:
        """Handle state update, only if this entity's dpcode was actually updated."""
        if self._dpcode_wrapper.skip_update(
            self.device, updated_status_properties, dp_timestamps
        ):
            return
        self.async_write_ha_state()