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

Code before:
    ) -> Self | None:
        """Find type information for a matching DP code available for this device."""
        if dpcodes is None:
            return None

        if not isinstance(dpcodes, tuple):
            dpcodes = (dpcodes,)

        lookup_tuple = (
            (device.function, device.status_range)
            if prefer_function
            else (device.status_range, device.function)
        )

        for dpcode in dpcodes:
            for device_specs in lookup_tuple:
                if (
                    (current_definition := device_specs.get(dpcode))
                    and parse_dptype(current_definition.type) is cls._DPTYPE
                    and (
                        type_information := cls._from_json(
                            dpcode=dpcode,
                            type_data=current_definition.values,
                            report_type=getattr(
                                current_definition, "report_type", None
                            ),
                        )
                    )
                ):
                    return type_information

        return None


@dataclass(kw_only=True)
class BitmapTypeInformation(TypeInformation[int]):
    """Bitmap type information."""

    _DPTYPE = DPType.BITMAP

    label: list[str]

    @classmethod
    def _from_json(
        cls, dpcode: str, type_data: str, *, report_type: str | None = None
    ) -> Self | None:
        """Load JSON string and return a BitmapTypeInformation object."""
        if not (parsed := cast(dict[str, Any] | None, json_loads_object(type_data))):
            return None
        return cls(
            dpcode=dpcode,

Review comment (suggestion):
According to the SDK, the attribute can be a string, or it can be None, but it is always present
https://github.com/tuya/tuya-device-sharing-sdk/blob/f635d83b837c45948af6cab77e45dd85e851253d/tuya_sharing/device.py#L44

```suggestion
                            report_type=current_definition.report_type
```

Code after:
    ) -> Self | None:
        """Find type information for a matching DP code available for this device."""
        if dpcodes is None:
            return None

        if not isinstance(dpcodes, tuple):
            dpcodes = (dpcodes,)

        lookup_tuple = (
            (device.function, device.status_range)
            if prefer_function
            else (device.status_range, device.function)
        )

        for dpcode in dpcodes:
            report_type = (
                sr.report_type if (sr := device.status_range.get(dpcode)) else None
            )
            for device_specs in lookup_tuple:
                if (
                    (current_definition := device_specs.get(dpcode))
                    and parse_dptype(current_definition.type) is cls._DPTYPE
                    and (
                        type_information := cls._from_json(
                            dpcode=dpcode,
                            type_data=current_definition.values,
                            report_type=report_type,
                        )
                    )
                ):
                    return type_information

        return None


@dataclass(kw_only=True)
class BitmapTypeInformation(TypeInformation[int]):
    """Bitmap type information."""

    _DPTYPE = DPType.BITMAP

    label: list[str]

    @classmethod
    def _from_json(
        cls, dpcode: str, type_data: str, *, report_type: str | None
    ) -> Self | None:
        """Load JSON string and return a BitmapTypeInformation object."""
        if not (parsed := cast(dict[str, Any] | None, json_loads_object(type_data))):
            return None
        return cls(