def get_device_class(hass: HomeAssistant, entity_id: str) -> (str | None):
    'Get device class of an entity.\n\n    First try the statemachine, then entity registry.\n    '
    if (state := hass.states.get(entity_id)):
        return state.attributes.get(ATTR_DEVICE_CLASS)
    entity_registry = er.async_get(hass)
    if (not (entry := entity_registry.async_get(entity_id))):
        raise HomeAssistantError(f'Unknown entity {entity_id}')
    return (entry.device_class or entry.original_device_class)
Get device class of an entity.

First try the statemachine, then entity registry.
def get_device_class(hass: HomeAssistant, entity_id: str) -> (str | None):
    'Get device class of an entity.\n\n    First try the statemachine, then entity registry.\n    '
    if (state := hass.states.get(entity_id)):
        return state.attributes.get(ATTR_DEVICE_CLASS)
    entity_registry = er.async_get(hass)
    if (not (entry := entity_registry.async_get(entity_id))):
        raise HomeAssistantError(f'Unknown entity {entity_id}')
    return (entry.device_class or entry.original_device_class)