Skip to content

# Utilities

## Functions

terminusgps.wialon.utils.generate_wialon_password(length: int = 32) → str

  Generates a Wialon compliant password between `8` and `64` characters.

  The generated password will contain:

  > - At least one uppercase letter.

  > - At least one lowercase letter.

  > - At least one special symbol.

  > - At least three digits.

  Parameters:

    length (`int`) – Length of the generated password. Default is `32`.

  Raises:

    ValueError – If :py:length is less than `8` or greater than `64`.

  Returns:

    A Wialon compliant password.

  Return type:

    `str`

terminusgps.wialon.utils.get_hw_type_id(name: str, session: WialonSession) → int | None

  Takes a Wialon hardware type name and returns its id, if it exists.

  Parameters:

    - name (`str`) – The name of a Wialon hardware type.

    - session (`WialonSession`) – A valid Wialon API session.

  Raises:

    WialonError – If something goes wrong during a Wialon API call.

  Returns:

    A Wialon hardware type id, if it was found.

  Return type:

    `int` | `None`

terminusgps.wialon.utils.get_id_from_iccid(iccid: str, session: WialonSession) → str | None

  DEPRECATED: Use `get_id_from_imei()`.

  Takes a Wialon unit’s IMEI # and returns its unit id, if it exists.

  Parameters:

    - iccid (`str`) – A unique id.

    - session (`WialonSession`) – A valid Wialon API session.

  Raises:

    WialonError – If something goes wrong during a Wialon API call.

  Returns:

    A Wialon object id, if it was found.

  Return type:

    `str` | `None`

terminusgps.wialon.utils.get_id_from_imei(imei: str, session: WialonSession) → str | None

  Takes a Wialon unit’s IMEI # and returns its unit id.

  Parameters:

    - imei (`str`) – A Wialon unit’s IMEI #.

    - session (`WialonSession`) – A valid Wialon API session.

  Raises:

    - ValueError – If `imei` contains non-digit characters.

    - WialonError – If something goes wrong during a Wialon API call.

  Returns:

    A Wialon object id, if it was found.

  Return type:

    `str` | `None`

terminusgps.wialon.utils.get_vin_info(vin_number: str, session: WialonSession) → dict

  Retrieves vehicle data from a VIN number.

  Parameters:

    - value (`str`) – A vehicle’s VIN number.

    - session (`WialonSession`) – A valid Wialon API session.

  Returns:

    A dictionary of vehicle information, if any was found.

  Return type:

    `dict`

terminusgps.wialon.utils.get_wialon_cls(items_type: str) → Type[WialonBase] | None

  Returns a Wialon object class based on `items_type`.

  Valid `items_type` are `"user"`, `"avl_unit"`, `"avl_unit_group"` and `"avl_resource"`.

  Parameters:

    items_type (`str`) – A Wialon object type.

  Returns:

    A subclass of `WialonBase`.

  Return type:

    `WialonBase` | `None`

terminusgps.wialon.utils.is_unique(value: str, session: WialonSession, items_type: str = 'avl_unit') → bool

  Determines if the value is unique among Wialon objects of type ‘items_type’.

  Parameters:

    - value (`str`) – A Wialon object name.

    - session (`WialonSession`) – A valid Wialon API session.

    - items_type (`str`) – Type of Wialon objects to validate the value against. Default is `"avl_unit"`.

  Raises:

    WialonError – If something goes wrong during a Wialon API call.

  Returns:

    Whether or not the value is unique among ‘items_type’.

  Return type:

    `bool`

## Usage

    from terminusgps.wialon.session import WialonSession
    from terminusgps.wialon.utils import get_id_from_iccid, generate_wialon_password

    # Generate random Wialon compliant passwords
    password_0 = generate_wialon_password(16)
    password_1 = generate_wialon_password(32)
    password_2 = generate_wialon_password(64)

    # Retrieve unit id from IMEI #
    with WialonSession() as session:
        unit_id = get_id_from_imei("869084062183235", session=session)
        print(f"{unit_id = }") # unit_id = 28006231