lce_service.device_class_api.icons module

exception lce_service.device_class_api.icons.InvalidIconError(message: str)

Bases: InvalidResourceError

Exception raised when the icon a request names does not resolve to a single icon.

Parameters:

message – A descriptive error message naming the icon.

exception lce_service.device_class_api.icons.InvalidIconRequestError

Bases: ValueError

Exception raised when the body of a request assigning an icon is not valid.

Parameters:

message – A descriptive error message.

lce_service.device_class_api.icons.get_device_class_icon(dbc: silo_cursor, device_class_id: int) → Dict[str, Any]

Get the icons of a device class.

Parameters:
  • dbc – A silo_cursor instance used to execute the database queries.

  • device_class_id – The id of the device class.

Returns:

The icons of the device class, see build_icon_result.

Raises:
lce_service.device_class_api.icons.get_icons(dbc: silo_cursor, search: str | None = None) → Dict[str, List[Dict[str, Any]]]

List the icons that can be assigned to device classes.

Parameters:
  • dbc – A silo_cursor instance used to execute the database query.

  • search – An optional text the names of the icons must contain, ignoring case. It is matched as text: % and _ are not wildcards. Surrounding whitespace is ignored, so a blank search lists every icon, like other optional parameters.

Returns:

A dictionary holding the “icons” (id, name, and size in bytes), ordered by name.

Raises:

DatabaseExecutionError – Raised when the database query fails.

lce_service.device_class_api.icons.set_device_class_icon(dbc: silo_cursor, device_class_id: int, icon: str | None, user: User) → Dict[str, Any]

Assign an icon to a device class, or unassign its icon.

This does what the setDeviceClassIcon GraphQL mutation does: the assignment of the device class is replaced, and the change is recorded in the audit log. The legacy fallback icon of the device class is left as is. Unlike the mutation, assigning the icon a device class already has changes nothing, and is not audited.

Parameters:
  • dbc – A silo_cursor instance, within the transaction of the request.

  • device_class_id – The id of the device class.

  • icon – The id or exact name of the icon to assign, or None to unassign the icon.

  • user – The user making the request.

Returns:

The icons of the device class after the change, see build_icon_result.

Raises:
lce_service.device_class_api.icons.validate_icon_payload(payload: Any) → str | None

Get the icon a request body assigns to a device class.

Parameters:

payload – The decoded JSON body of the request.

Returns:

The id or name of the icon to assign, or None to unassign the icon.

Raises:

InvalidIconRequestError – Raised when the body is not an object with an icon that is a non-empty string or null.