Skip to content

ha_types

to_dict

to_dict(obj: Any) -> Dict[str, Any]

Convert a dataclass object to dict

Parameters:

  • obj (Any) –

    The sensor object to convert

Returns:

  • Dict[str, Any]

    A dictionary representation of the object

Source code in src/grottext/ha/ha_types.py
107
108
109
110
111
112
113
114
115
116
117
118
def to_dict(obj: Any) -> Dict[str, Any]:
    """Convert a dataclass object to dict

    Parameters:
        obj: The sensor object to convert

    Returns:
        A dictionary representation of the object
    """
    dict_obj = asdict(obj)
    # Remove None values
    return {k: v for k, v in dict_obj.items() if v is not None}