def charge_storage(assign_power, preload, step_length):
    """Charges/discharges the storage and returns the realised (dis)charging power.

    Args:
        assign_power: (dict): power assigned to storage and cps
        preload: (float): Preload at current time step.
        step_length: (:obj: `datetime.timedelta`): Resolution of the simulation denoting the
                time in between two adjacent time steps.
    Returns:
        assign_power: (dict): keys=storage, value=realised power

    """
    assign_power_storage = assign_power['storage']
    assign_power_cps = assign_power['cps']
    for storage_system in assign_power_storage:
        power_to_storage = assign_power_storage[storage_system]
        storage = storage_system.storage

        # Storage is not needed to charge cps so see if charging is possible
        if power_to_storage == 0:
            transformer = storage_system.get_transformer()
            power_available = transformer.max_hardware_power(assign_power_cps, preload)
            # Charge storage depending on available power and its limits
            power_charged = storage.charge(power_available, step_length)
            # Update assigned power
            assign_power['storage'][storage_system] = power_charged
        # Try to discharge with assigned power
        else:
            storage.discharge(abs(power_to_storage), step_length)

    return assign_power